2016-11-06 85 views
0

嗨,我是一個Python tkinter的初學者,並且正在開發一個頂尖項目來開發一個準備就緒評估工具。我已經在一定程度上編寫了代碼。我有優先考慮的問題。 以下是一些示例問題: •20%貴組織是否在去年完成了戰略規劃流程? (是(5),否(0),也許(1)) •10%您是否有內部/醫師/管理員/臨牀冠軍來推動變革? (是(5),否(0),也許(2.5))評分調查問卷python tkinter,分配問題的重要性

現在例如,如果用戶選擇是(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

使用'命令='分配功能。 – furas

回答

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 
在`Button`