在第二个窗口中保存用户输入
我的代码有问题,当我运行程序时而不是单击按钮时保存用户输入我还尝试创建一个函数来检测是否entry1.get() == none不保存输入“输入“但这不起作用,感谢您的帮助并为
我的代码计时:
#imports
#define the first tk window
window = Tk()
window.geometry("655x600")
window.title("")
icon = PhotoImage(file="data/icons/icon.png")
window.iconphoto(True,icon)
window.config(background="#2e3033")
#savefiles
savefile1 = open("data/userinput/data1.txt","w", encoding="utf-8")
#button functions
def new_window1():
global entry1
window2 = Tk()
window2.geometry("500x100+200+300")
window2.config(background="#2e3033")
window2.title("Edit Button 1")
entry1 = Entry(window2,width=100, font= ("Arial",12))
entry1.place(x=5,y=30)
Button1 = Button(window2, text="save",command=lambda:[savefile1.write(entry1.get()),window2.destroy()])
Button1.place(x=5,y=70)
#buttons
image1 = PhotoImage(file="images/streamdeximage1.png")
button1 = Button(window, text="hello" , command=new_window1 , image=image1)
button1.place(x=20,y=20)
window.mainloop()
I have a problem with my code the user input is saved when I run the program instead of when the button is clicked I also tried to make a function that detects if entry1.get() == none don't save the input "input" but this did not work thanks for your help and time
my code:
#imports
#define the first tk window
window = Tk()
window.geometry("655x600")
window.title("")
icon = PhotoImage(file="data/icons/icon.png")
window.iconphoto(True,icon)
window.config(background="#2e3033")
#savefiles
savefile1 = open("data/userinput/data1.txt","w", encoding="utf-8")
#button functions
def new_window1():
global entry1
window2 = Tk()
window2.geometry("500x100+200+300")
window2.config(background="#2e3033")
window2.title("Edit Button 1")
entry1 = Entry(window2,width=100, font= ("Arial",12))
entry1.place(x=5,y=30)
Button1 = Button(window2, text="save",command=lambda:[savefile1.write(entry1.get()),window2.destroy()])
Button1.place(x=5,y=70)
#buttons
image1 = PhotoImage(file="images/streamdeximage1.png")
button1 = Button(window, text="hello" , command=new_window1 , image=image1)
button1.place(x=20,y=20)
window.mainloop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使你的代码保存了我这边第二个窗口的按钮单击时的数据,这里有一些更改
Even though ur code saves the data on button click of second window on my side, here are some changes