0
我正在python中使用tkinter模塊進行測驗,我被困在如何創建一個按鈕來檢查答案是否正確。但我會把它放在一個程序中,但問題已經在一個。Python tkinter測驗
import tkinter as tk
window = tk.Tk()
window.title("6 Questions")
window.geometry("500x150")
score = 0
def inst():
t = tk.Label(window, text="All you need to do is just answer each question with either a '1, 2, 3' or the actual word.")
t.pack()
def start():
root = tk.Tk()
root.title("question 1")
q = tk.Label(root, text="what type of input holds whole numbers")
q.pack()
a = tk.Label(root, text="1.) int")
a.pack()
b = tk.Label(root, text="2.) string")
b.pack()
c = tk.Label(root, text="3.) float")
c.pack()
ans = tk.Entry(root, width=40)
ans.pack()
#here is the button I want to verify the answer
sub = tk.Button(root, text="Submit")
sub.pack()
greet = tk.Label(window, text="Welcome to the 6 Question Quiz.")
greet.pack()
start = tk.Button(window, command=start, text="Start")
start.pack()
instr = tk.Button(window, text="Instructions", command=inst)
instr.pack()
end = tk.Button(window, text="Exit", command=exit)
end.pack()
請記住,SO是_not_代碼寫作服務。你需要做的是創建一個函數來驗證答案並使用'sub = tk.Button(root,text =「Submit」,command = verify)'如果'verify'是函數的名字。 –
如果我在另一個程序中這樣做,它將無法從條目中獲取信息 – morgan
然後在當前程序中聲明程序。不過,我應該告訴你,你打算使用tkinter的類,例如'class Start(tk.Tk):'等 –