0
我在製作一個程序來模擬一個控制檯。這是到目前爲止我的代碼(我現在就開始吧,學習Tkinter的,雖然我不知道,如果Tkinter的最佳選擇):Python 3.4 Tkinter - 對象沒有屬性
from tkinter import *
class App:
def __init__(self, master):
self.frame = Frame(master, bg = 'black')
self.bottomframe = Frame(master, bg = 'black')
self.elabel = Label(master, text = '>', bg = 'black', font = 'system', fg = 'white')
self.einput = Entry(master, bd =0, bg = 'black', font = 'system', fg = 'white', command = self.update_text())
# Packing
self.frame.pack()
self.bottomframe.pack(side = BOTTOM)
self.elabel.pack(side = LEFT)
self.einput.pack(side = LEFT)
def update_text(self):
self.einput.insert(0, '>')
root = Tk()
app = App(root)
root.mainloop()
的錯誤是
Traceback (most recent call last):
File "C:/Users/*/PycharmProjects/ConsoleDungeon/game.py", line 21, in <module>
app = Game(root)
File "C:/Users/*/PycharmProjects/ConsoleDungeon/game.py", line 9, in __init__
self.einput = Entry(master, bd =0, bg = 'black', font = 'system', fg = 'white', command = self.update_text())
File "C:/Users/*/PycharmProjects/ConsoleDungeon/game.py", line 17, in update_text
self.einput.insert(0, '>')
AttributeError: 'Game' object has no attribute 'einput'
還有一件事:在線路
self.einput = Entry(master, bd =0, bg = 'black', font = 'system', fg = 'white', command = self.update_text())
我不知道如何使用命令說法。
從你的'command'參數去掉括號,這將解決這兩個錯誤 – 2014-09-10 15:17:10
輸入構件沒有一個命令參數?你確定你不是指validatecommand? – 2014-09-10 15:20:10