Python Tkinter 窗口未关闭 [英] Python Tkinter Window not closing

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

问题描述

所以当我注意到这个有趣的行为时,我正在编写一个简短的代码来测试一些东西.

So I was writing a short code to test something when I noticed this interesting behaviour.

import tkinter
from tkinter import *

master=tkinter.Tk()
master.geometry("800x850+0+0")
master.configure(background="lightblue")

def d():
    master.destroy()

button=Button(master, text="asdf", command=d).pack()

master.mainloop()

按钮按预期关闭窗口,但是当我单击左上角按钮上的红色按钮(来自实际窗口,而不是 tkinter)时,程序卡住并且没有响应.但是,当我更改代码以删除按钮中的文本时,如下所示:

The button closes the window as expected, but when I click on the red button on the top left button (from the actual window, not tkinter), the program gets stuck and doesn't respond. However, when I change the code to remove the text in the button as follows:

import tkinter
from tkinter import *

master=tkinter.Tk()
master.geometry("800x850+0+0")
master.configure(background="lightblue")

def d():
    master.destroy()

button=Button(master, command=d).pack()

master.mainloop()

它现在工作得很好.窗口中的 tkinter 按钮和实际窗口中的红色按钮都按预期关闭窗口.为什么会发生这种情况?我在 Mac 上使用 python 3.5,以防万一.

It now works perfectly fine. Both the tkinter button in the window and the red button from the actual window close the window as expected. Why does this happen? I am using python 3.5 on Mac, in case this matters.

推荐答案

我在我的一些朋友的电脑上试过,他们没有这个问题,所以看起来这只是一个特定于硬件的问题.

I tried it out on some of my friends computers and they didn't have this issue, so it appears that it was just a hardware specific problem.

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

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