您好我是python tkinter的初学者,正在开发一个能够开发准备评估工具的顶点项目。我在某种程度上编写了代码。我有一些优先考虑的问题。 以下是示例问题: •20%您的组织在去年完成了战略规划流程吗? (是(5),否(0),也许(1)) •10%您是否有内部/医师/管理员/临床冠军来促进变革? (是(5),否(0),可能(2.5))
现在例如,如果用户选择是(5)应该乘以20%来获得实际分数,然后应该添加所有分数以获得100分。
我很惊讶如何使用结果按钮获得结果。 以下是我的代码的一部分:
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="ORGANIZATIONAL READINESS", font=LARGE_FONT)
label.pack(pady=10,padx=1)
label1 = tk.Label(self, text = "Has your organization completed a strategic planning process in the last year?")
label1.pack(pady=10,padx=10)
var = tk.StringVar()
R1 = ttk.Radiobutton(self, text = "Yes", variable = var, value = "Yes")
R2 = ttk.Radiobutton(self, text = "No", variable = var, value = "No")
R3 = ttk.Radiobutton(self, text = "May be", variable = var, value = "Maybe")
label1.pack(anchor='w')
R1.pack(anchor='w')
R2.pack(anchor='w')
R3.pack(anchor='w')
ResultsButton = tk.Button(self, text = "Results")
ResultsButton.pack(padx=30,pady=10)
button1 = ttk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
progressbar = ttk.Progressbar(self, orient= HORIZONTAL, length= 200)
progressbar.pack()
progressbar.config(mode = 'determinate', maximum = 15.0, value = 4.0 )
感谢任何帮助。谢谢! :)
答案 0 :(得分:0)
您需要在ResultsButton中使用command = SOMEFUNCTIONHERE。例如:
ResultsButton = tk.Button(self, text = "Results", command = self.getResults)
ResultsButton.pack(padx=30,pady=10)
现在你需要定义函数self.getResults(注意tk.Button行中没有括号)
def getResults(self): # This is a function inside your PageOne class
user_answer = var.get() # Gets the value of var based on which radio button was selected
if user_answer == "Yes":
# Give them 5 * 0.2 points
if user_answer == "No":
# Give them 0 * 0.2 points