[英]Python tkinter: buttons are not displaying
I'm new to tkinter and I'm trying to display two buttons on the window. 我是tkinter的新手,正在尝试在窗口上显示两个按钮。 Currently the buttons are not displaying on the window. 当前,按钮未显示在窗口上。 I would be very grateful if someone could point out my errors. 如果有人可以指出我的错误,我将不胜感激。 Thank you. 谢谢。
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!")
There is a problem in your __init__bmethod, and from what I see you do not launch the application anywhere. 您的__init__b方法存在问题,从我看来,您不会在任何地方启动该应用程序。 Does this work for you? 这对您有用吗?
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.