2024-04-26 17:58:11 发布
网友
我正在使用的程序当前需要用户的输入才能显示在程序窗口上。我研究过互联网和stackoverflow,发现了几种解决我问题的方法,但似乎都不管用。我的目标是通过Python的tkinter条目小部件接收用户的输入,并在一个新的标签中显示结果,同时去掉我的初始标签和输入框,但是程序拒绝了我的回答尝试。在
为了实现我的目标,您有什么策略、代码行/库或建议?在
我现有的解决方案:
.get() textvariable=self.entdat
现有规范如下:
我修改了你的代码,这样它至少能以你想要的方式执行。在
from Tkinter import * class Input(Frame): def __init__(self, parent=None, **kw): Frame.__init__(self, parent, background="white") self.parent = parent self.entdat = StringVar() self.makeWidgets() def makeWidgets(self): self.ol = Label(text="Objective:") self.ol.pack(side=TOP) self.ew = Entry(textvariable=self.entdat) self.ew.pack(side=TOP) self.b = Button(text="OK", command=self.clicked) self.b.pack(side=TOP) def clicked(self): self.dat = Label(self, textvariable=self.entdat ) self.dat.pack(side=TOP) self.distroy_Widget() def distroy_Widget(self): self.ew.destroy() self.ol.destroy() self.b.destroy() def main(): root = Tk() root.geometry("240x135+25+50") tm = Input(root) tm.pack(side=TOP) root.mainloop() if __name__ == '__main__': main()
希望有帮助。在
我修改了你的代码,这样它至少能以你想要的方式执行。在
希望有帮助。在
相关问题 更多 >
编程相关推荐