2017-06-26 306 views
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() 

回答

2

所以,我從你的問題得到的是,你必須與Kelime問題的第一窗口,要在create_widgets()函數打開了else子句另一個窗口,一旦你點擊提交按鈕。這裏的問題是,當你運行root_close()時,你基本上終止了整個程序(程序運行,因爲根在由root.mainLoop()創建的循環中)。如果您想在關閉另一個窗口時打開一個窗口,請查看Closing current window when opening another window

相關問題