【发布时间】:2018-02-08 09:07:49
【问题描述】:
我在 mac 上使用 python 3.6。我最近刚刚开始使用 GUI,并从一个简单的 messagebox.showinfo 弹出窗口开始。但是,当我运行程序时,会显示消息框,但是当我单击“确定”时,它并没有消失,我只是被旋转的沙滩球困住,直到我手动关闭程序。
我知道这不是我的代码的问题,因为它在 windows 操作系统上运行良好,因为我也在 windows 计算机上运行了代码。
这是弹出消息框的函数:
def greeting():
greetingFile = open("greetingFile.txt", "w")
greetingFile.write(messagebox.showinfo("Welcome to the board game!","In this game, you will navigate"\
" across a 7x7 grid and the first player to reach square 49 wins."\
" Both players start on space 1."))
greetingFile.close()
return
这是我调用函数的代码的主要部分:
greeting()
greetingFile = open("greetingFile.txt", "r")
greetingFile.close()
这是我编写的新代码,它应该做同样的事情:显示一个消息框,然后关闭。
import tkinter
from tkinter import messagebox
root = tkinter.Tk()
root.withdraw()
def greeting():
greetingFile = open("greetingFile.txt", "w")
greetingFile.write(messagebox.showinfo("Welcome to the board game!", "In this game, you will navigate"\
" across a 7x7 grid and the first player to reach square 49 wins."\
" Both players start on space 1."))
greetingFile.close()
return
greeting()
greetingFile = open("greetingFile.txt", "r")
greetingFile.close()
当我运行它时,它可以工作,但是当我单击“确定”关闭消息框时,它会冻结并出现旋转的沙滩球。当我在 Windows pc 上运行它时不会发生这种情况
【问题讨论】:
-
请将代码发布为格式化文本。
-
有代码,但我不认为代码有什么问题,而是操作系统有问题
-
看,macOS 是由至少 数十 名专业程序员在 16 年 中构建的。因此,您的代码中更有可能存在问题。另外,这不是完整代码,请提供minimal reproducible example。
-
我提供了一个新代码,这是我正在尝试做的,但它仍然不会让我关闭消息框。
-
你为什么要将消息框写入文件?
标签: python macos python-3.x tkinter