0
我想寫一個腳本,會問一個英文單詞,然後顯示其含義。我可以提問,但答案窗口不顯示。下面我寫的代碼。在第二個窗口中,它開始像一個新的頁面。我如何修改它?現在,它顯示標籤,但似乎沒有按鈕。關閉並打開另一個窗口
from tkinter import *
class Application(Frame):
def __init__(self, master):
"""Initialize the Frame"""
Frame.__init__(self, master)
self.grid()
self.button_clicks = 0 # count the number of button clicks
self.create_widgets()
def root_close(self):
global root
root.destroy()
self.button_clicky()
def create_widgets(self):
"""Button displays number of clicks"""
if clicker % 2 == 0:
self.soru = Label(self, text="Kelime: " + kelime)
self.soru.grid(row=0, column=0, columnspan=2, sticky=W)
self.btn_submit = Button(self, text="Submit", command=self.root_close)
self.btn_submit.grid(row=3, column=1, sticky=W)
else:
self.cevap = Label(self, text="Kelimenin türkçe anlamları:\n" + anlam)
self.cevap.grid(row=0, column=0, columnspan=2, sticky=W)
self.btn_okay = Button(self, text="Bildim", command=self.dogru)
self.btn_submit.grid(row=3, column=0, sticky=W)
self.btn_okay = Button(self, text="Bilemedim", command=self.yanlis)
self.btn_submit.grid(row=3, column=2, sticky=W)
def button_clicky(self):
global clicker
clicker += 1
def dogru(self):
#will do stuff
self.root_close()
def yanlis(self):
self.root_close()
clicker = 0
kelime = "apple"
anlam = "elma"
root = Tk()
root.title("Ask word")
root.geometry("200x85")
app = Application(root)
root.mainloop()