2017-01-21 11 views
-1

以下のPythonプログラムを実行しているときに空白のページが表示されています。私はPython 3.3でこのコードを実行しています。Tkinterの空白のウィンドウ

from tkinter import * 

class Window(Frame): 
    def __init__(self, master = None): 
     Frame.__init__(self, master) 

     self.master = master 

     self.init_window() 

    def init_window(self): 
     self.master.title("GUI") 
     self.pack(fill = BOTH,expand = 1) 
     #quitbutton = Button(self, text = "Quit", command= self.client_exit) 
     #quitbutton.place(x=0,y=0) 
     menu = Menu(self.master) 
     self.master.config(menu = menu) 

     file = Menu(menu) 
     file.add_command(label = 'Exit', command = self.client_exit()) 
     menu.add_cascade(label='File', menu = file) 

     edit = Menu(menu) 
     edit.add_command(label = 'Undo') 
     edit.add_cascade(label = 'Edit', menu = edit) 

    def client_exit(self): 
     exit() 

root = Tk() 
root.geometry("400x300") 
app = Window(root) 
root.mainloop() 
+0

エラーが発生していますか? –

+2

それはプログラムを終了するためにエラーメッセージを出します - 'command ='は関数名を必要とします - それは '()'がないことを意味します - 正しく 'command = self.client_exit'を実行します:' exitの代わりに 'root.destroy() ) ' - ウィンドウを閉じます。 – furas

+1

答えがあなたの問題を解決する場合は、回答を受け入れて質問を閉じてください。 – ppasler

答えて

1

あなたはquitbutton

file = Menu(menu) 
file.add_command(label = 'Exit', command = self.client_exit) 
menu.add_cascade(label='File', menu = file) 

に示すように、()せずにそれを行う。また、変数名

ため fileのようなPythonのキーワードを使用していない commandため、関数名 self.client_exit()()を置きます
関連する問題