[英]Python tkinter: buttons are not displaying
我是tkinter的新手,正在嘗試在窗口上顯示兩個按鈕。 當前,按鈕未顯示在窗口上。 如果有人可以指出我的錯誤,我將不勝感激。 謝謝。
class Application(Frame):
def __init__(self, master):
super(Application, self).__init__(master)
self.grid()
self.create_widgets()
def creat_widgets(self):
self.button1 = Button(self, text="I do nothing")
self.button1.grid()
self.button2 = Button(self)
self.button2.grid()
self.button2.config(text="Me too!")
您的__init__b方法存在問題,從我看來,您不會在任何地方啟動該應用程序。 這對您有用嗎?
from Tkinter import *
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.button1 = Button(self, text="I do nothing")
self.button1.grid()
self.button2 = Button(self)
self.button2.grid()
self.button2.config(text="Me too!")
if __name__ == '__main__':
root = Tk()
Application(root).mainloop()
您的函數creat_widgets
的拼寫與__init__
中的拼寫不同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.