我想创建一个非常简单的GUI。只需一个按钮。 实际上,我试图复制此代码https://pythonprogramming.net/tkinter-python-3-tutorial-adding-buttons/
但是,我使用Python 2.7与使用Python 3.x的文章不同 在Python 2.7中运行时相同的代码不显示退出按钮,在视频中显示退出按钮。
这是我的代码
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):
# changing the title of our master widget
self.master.title("Gui")
# allowing the widget to take the full space of the root window
self.pack()
# creating a button instance
button = Button(self , text = 'quit')
# placing the button on my window
button.place(x=0, y=0)
if __name__ == '__main__':
root = Tk()
#size of the window
root.geometry("400x300")
app = Window(root)
root.mainloop()
这是教程中的代码
from tkinter import *
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window()
#Creation of init_window
def init_window(self):
# changing the title of our master widget
self.master.title("GUI")
# allowing the widget to take the full space of the root window
self.pack(fill=BOTH, expand=1)
# creating a button instance
quitButton = Button(self, text="Quit")
# placing the button on my window
quitButton.place(x=0, y=0)
root = Tk()
#size of the window
root.geometry("400x300")
app = Window(root)
root.mainloop()
有人可以解释行为上的差异吗?