【发布时间】:2013-12-03 05:51:11
【问题描述】:
本质上,该程序是一组单选按钮,当用户单击提交按钮时,程序应返回与用户所做选择字符串匹配的答案。我已经让它大部分工作了,但最终做出的决定仍然是错误的。让我知道我是否可以回答更多问题。
from Tkinter import *
import tkMessageBox
root = Tk()
q1 = IntVar()
Label(root,
text="""How many samples do you have?""",
justify = LEFT,
padx = 20).pack()
Radiobutton(root,
text="One",
padx = 20,
variable=q1,
value=1).pack(anchor=W)
Radiobutton(root,
text="Two",
padx = 20,
variable=q1,
value=2).pack(anchor=W)
q2 = IntVar()
Label(root,
text="""Which choice most closely fits your sample size?""",
justify = LEFT,
padx = 20).pack()
Radiobutton(root,
text = """Less than 30""",
padx = 20,
variable=q2,
value = 1).pack(anchor=W)
Radiobutton(root,
text = """Greater than or equal to 30""",
padx = 20,
variable=q2,
value = 2).pack(anchor =W)
q3 = IntVar()
Label(root,
text="""Is the population mean known?""",
justify = LEFT,
padx = 20).pack()
Radiobutton(root,
text = """Yes""",
padx = 20,
variable=q3,
value = 1).pack(anchor=W)
Radiobutton(root,
text = """No""",
padx = 20,
variable=q3,
value = 2).pack(anchor=W)
q4 = IntVar()
Label(root,
text="""Is the standard deviation of your data known?""",
justify = LEFT,
padx = 20).pack()
Radiobutton(root,
text = """Yes""",
padx = 20,
variable=q4,
value = 1).pack(anchor=W)
Radiobutton(root,
text = """No""",
padx = 20,
variable=q4,
value = 2).pack(anchor =W)
q5 = IntVar()
Label(root,
text="""Do you wish to compare two groups?""",
justify = LEFT,
padx = 20).pack()
Radiobutton(root,
text = """Yes""",
padx = 20,
variable=q5,
value = 1).pack(anchor=W)
Radiobutton(root,
text = """No""",
padx = 20,
variable=q5,
value = 2).pack(anchor =W)
q6 = IntVar()
Label(root,
text="""Do you want to compare two sample means?""",
justify = LEFT,
padx = 20).pack()
Radiobutton(root,
text = """Yes""",
padx = 20,
variable=q6,
value = 1).pack(anchor=W)
Radiobutton(root,
text = """No""",
padx = 20,
variable=q6,
value = 2).pack(anchor =W)
q7 = IntVar()
Label(root,
text="""Is your data paired (E.g. before and after data)?""",
justify = LEFT,
padx = 20).pack()
Radiobutton(root,
text = """Yes""",
padx = 20,
variable=q7,
value = 1).pack(anchor=W)
Radiobutton(root,
text = """No""",
padx = 20,
variable=q7,
value = 2).pack(anchor =W)
q8 = IntVar()
Label(root,
text="""Are you testing proportions?""",
justify = LEFT,
padx = 20).pack()
Radiobutton(root,
text = """Yes""",
padx = 20,
variable=q8,
value = 1).pack(anchor=W)
Radiobutton(root,
text = """No""",
padx = 20,
variable=q8,
value = 2).pack(anchor =W)
q9 = IntVar()
Label(root,
text="""Do you wish to test for a difference between observed and expected data?""",
justify = LEFT,
padx = 20).pack()
Radiobutton(root,
text = """Yes""",
padx = 20,
variable=q9,
value = 1).pack(anchor=W)
Radiobutton(root,
text = """No""",
padx = 20,
variable=q9,
value = 2).pack(anchor =W)
Button(root, text = "Submit", command=choose).pack()
def choose():
if q1 == 1 and q2 == 1 and q3 == 2 and q4 == 2 and q5 == 1 and q6 == 2 and q7 == 2 and q8 == 2 and q9 == 2 :
tkMessageBox.showinfo( 'You should use the t-test!')
elif q1 == 1 and q2 == 2 and q3 == 1 and q4 == 1 and q5 == 2 and q6 == 2 and q7 == 2 and q8 == 2 and q9 == 2:
tkMessageBox.showinfo('You should use the z-test!')
elif q1 == 1 and q2 == 1 and q3 == 2 and q4 == 2 and q5 == 1 and q6 == 2 and q7 == 1 and q8 == 2 and q9 == 2:
tkMessageBox.showinfo( 'You should use the paired t-test!')
elif q1 == 2 and q2 == 1 and q3 == 2 and q4 == 2 and q5 == 1 and q6 == 1 and q7 == 2 and q8 == 2 and q9 == 2:
tkMessageBox.showinfo( 'You should use the two-sample t-test!')
elif q1 == 2 and q2 == 2 and q3 == 1 and q4 == 1 and q5 == 2 and q6 == 1 and q7 == 2 and q8 == 2 and q9 == 2:
tkMessageBox.showinfo('You should use the two-sample z-test!')
elif q1 == 1 and q2 == 2 and q3 == 1 and q4 == 1 and q5 == 2 and q6 == 2 and q7 == 2 and q8 == 1 and q9 == 2:
tkMessageBox.showinfo('You should use the 1-prop z-test!')
elif q1 == 2 and q2 == 2 and q3 == 1 and q4 == 1 and q5 == 2 and q6 == 2 and q7 == 2 and q8 == 1 and q9 == 2:
tkMessageBox.showinfo('You should use the 2-prop z-test!')
elif q1 == 1 and q2 == 2 and q3 == 2 and q4 == 2 and q5 == 2 and q6 == 2 and q7 == 2 and q8 == 2 and q9 == 1:
tkMessageBox.showinfo( 'You should use the chi-square test!')
else:
tkMessageBox.showinfo('You have either incorrectly answered a question about your data or none of the available tests are appropriate.')
sys.exit()
root.mainloop()
【问题讨论】:
标签: python tkinter radio-button