使用 tkinter 关闭和打开窗口 [英] Close and open windows with tkinter

查看:70
本文介绍了使用 tkinter 关闭和打开窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主窗口,其中有一个按钮,我打开另一个窗口,该窗口由另一个按钮关闭.一旦后者关闭,您怎么可能无法重新打开它?我附上两个程序的代码.

I have a main window, and a button inside of this one, I open another window, which is closed by another button. How is it possible that once the latter is closed you can not reopen it? I attach the code of the two programs.

from tkinter import *
def funzBottoCli():import nuovaprova

root = Tk()

root.state('zoomed')

root.title("Gestionale")

bottonCli = Button(root, text="  Apertura altra finestra   ", fg=('red'),    
font=('arial',10,'bold'), relief='raised', command=funzBottoCli).place(x=20, y=20)

root.mainloop()

#SECOND PROGRAM
from tkinter import *
def funzBottoCli():fine_cli_ins.destroy()

fine_cli_ins = Tk()

fine_cli_ins.title("Inserimento Anagrafica Clienti")

fine_cli_ins.geometry('640x480+400+150')

form1 = Frame(fine_cli_ins, bg='red',width=640, height=50, relief='raised',        
border=3).pack() 

label1 = Label(fine_cli_ins, text=(" INSERIMENTO CLIENTI "), fg=('red'),   
bg=('gray'),   
font=('arial',16,'bold'), relief='raised').place(x=200, y=10)

bottonCli = Button(fine_cli_ins, text="      Chiusura finestra      ", fg=('red'),   
font=('arial',10,'bold'), relief='raised', command=funzBottoCli).place(x=260, y=400)

fine_cli_ins.mainloop()

推荐答案

如果要打开和关闭多个窗口.正确的做法是先创建一个 Tk 实例,然后创建一个或多个 Toplevel 实例.当 Tk 的实例被销毁时,你的程序应该退出.

If you want to open and close multiple windows. the proper way to do it is to create a single instance of Tk and then one or more instances of Toplevel. Your program should then exit when the instance of Tk is destroyed.

这篇关于使用 tkinter 关闭和打开窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆