gpt4 book ai didi

Python Tkinter GUI 界面

转载 作者:行者123 更新时间:2023-12-01 09:18:33 26 4
gpt4 key购买 nike

我的 Tkinter GUI 界面有问题。文本不会在 shell 中打印,但如果将 Entry 放置在第一个 tk 窗口 get() 中,它就可以工作...帮助我吗?

这是我的代码:

import os
from tkinter import *
##CONFIG FRS TK
import tkinter as tk
window = Tk()
window.geometry("600x500")
window.title("Gestione caldaie")
window.config(bg="gray")

name2=StringVar()
def enter():
print(name2.get())

def test():
clienti_caldaie=Tk()
clienti_caldaie.resizable(False,False)
clienti_caldaie.geometry("800x550")
clienti_caldaie.title("Clienti e Caldaie")
clienti_caldaie.config(bg = "#9999ff")

##DATI UTENTE
name = Label(clienti_caldaie, text = "Nome e Cognome ", font = "bold", bg = "#9999ff").place(x = 0, y = 3)

named = Entry(clienti_caldaie,textvariable=name2).place(x = 150, y = 4)
but=Button(text="Save",command=enter).place(x = 70, y = 10)

clienti = Button(text = "New", command=test).place(x = 30, y = 60)
window.mainloop()

最佳答案

正如我在评论中提到的,您不应使用多个 Tk() 实例。您应该对新对话框使用 Toplevel。

例如

import os
from tkinter import *
##CONFIG FRS TK
import tkinter as tk
window = Tk()
window.geometry("600x500")
window.title("Gestione caldaie")
window.config(bg="gray")

name2=StringVar()
def enter():
print(name2.get())

def test():
clienti_caldaie=Toplevel()
clienti_caldaie.resizable(False,False)
clienti_caldaie.geometry("800x550")
clienti_caldaie.title("Clienti e Caldaie")
clienti_caldaie.config(bg = "#9999ff")

##DATI UTENTE
name = Label(clienti_caldaie, text = "Nome e Cognome ", font = "bold", bg = "#9999ff").place(x = 0, y = 3)

named = Entry(clienti_caldaie,textvariable=name2).place(x = 150, y = 4)
but=Button(clienti_caldaie,text="Save",command=enter).place(x = 70, y = 10)

clienti = Button(text = "New", command=test).place(x = 30, y = 60)
window.mainloop()

关于Python Tkinter GUI 界面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51009903/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com