我正在使用的程序目前需要用戶輸入以顯示在程序窗口中。我研究了互聯網和計算器,發現了幾個解決方案來解決我的問題,但似乎沒有任何工作。我的目標是通過Python的tkinter入口小部件接收來自用戶的輸入,並將結果顯示在一個新的標籤中,同時取出我的第一個和輸入框,但是,該程序拒絕我的答案。從Python的tkinter入口小部件接收輸入並將其顯示在標籤中
你有什麼策略,代碼/圖書館的條款,或者你有什麼建議來實現我的目標?
我現有的解決方案:
.get()
textvariable=self.entdat
現有的代碼如下:
from Tkinter import *
import time
class Input(Frame):
def __init__(self, parent=None, **kw):
Frame.__init__(self, parent, background="white")
self.parent = parent
self.initUI()
self.entdat = StringVar
self.timestr = StringVar()
self.makeWidgets()
def makeWidgets(self):
self.ol = Label(text="Objective:")
self.ol.pack(side=TOP)
self.ew = Entry()
self.ew.pack(side=TOP)
self.b = Button(text="OK", command=self.clicked)
self.b.pack(side=TOP)
def clicked(self):
self.entdat = self.ew.get()
self.dat = Label(textvariable=self.ew.get())
self.dat.pack(side=TOP)
self.hide_Widget()
def hide_Widget(event):
event.ew.pack_forget()
event.ol.pack_forget()
event.b.pack_forget()
def main():
root = Tk()
root.geometry("240x135+25+50")
tm = Input(root)
tm.pack(side=TOP)
root.mainloop()
if __name__ == '__main__':
main()
什麼是'self.initUI()'?它沒有在你提供的代碼中定義。 – Marcin
對不起。我只包含了包含該問題的程序部分。 self.intitUI()將parent.title設置爲「Input」。 –