嘿伙计们我只是想创造一个简单的按钮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
感谢您的帮助
答案 0 :(得分:0)
在你的&#34;#button2&#34;评论;下面3行,您使用
self.button.configure()
但是没有名为&#34; button&#34;的变量。我想你想说:
self.button2.configure()