Python属性按钮

2024-10-05 14:28:15 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿,伙计们,我只是想创建一个简单的按钮gui(绝对n00b) 但我似乎能找出我的代码有什么问题:

``__author__ = 'Isaac'

from Tkinter import *

class Application(Frame):
""" My smart board application"""
def __init__(self, master):
    Frame.__init__(self, master)
    self.grid()
    self.create_widgets()

def create_widgets(self):
#Button1
    self.button1 = Button(self, text = "Calandar")
    self.button1.grid()

#button2
    self.button2 = Button(self)
    self.button2.grid()
    self.button.configure(text = "Weather")
root = Tk()
root.title("Smartboard")
root.geometry("500x400")

app = Application(root)

root.mainloop()

我得到的错误是:

C:\Python27\python.exe "C:/Users/Isaac/Desktop/Useful     python/Clanadar/GUIOOP.py"
Traceback (most recent call last):
 File "C:/Users/Isaac/Desktop/Useful python/Clanadar/GUIOOP.py", line 25, in <module>
app = Application(root)
File "C:/Users/Isaac/Desktop/Useful python/Clanadar/GUIOOP.py", line 11, in __init__
self.create_widgets()
File "C:/Users/Isaac/Desktop/Useful python/Clanadar/GUIOOP.py", line 20, in      create_widgets
self.button.configure(text = "Weather")
AttributeError: Application instance has no attribute 'button'

Process finished with exit code 1

谢谢你的帮助


Tags: textpyselfapplicationinitcreaterootwidgets