tkinter 消息框 - 错误的填充值“2m”

问题描述

我正在努力使 tkinter.messageBox 工作。这是重现错误所需的最少代码

import tkinter as tk
from tkinter import messageBox

def call_handler():
    messageBox.showerror("Title","message")


w = tk.Tk()
w.geometry("200x200")
frame = tk.Frame(w)
btn = tk.Button(frame,command=call_handler,text="Click me!")
btn.pack()
frame.pack(padx=10,pady=10)
w.mainloop()

这是我点击 btn 后得到的:

tkinter messageBox

messageBox 是窗口中间的细条。当我调整它的大小时,它完全是空的。

tkinter messageBox resized

在我的终端中,我收到以下错误

Exception in Tkinter callback
Traceback (most recent call last):
  File ".pyenv/versions/3.8.0/lib/python3.8/tkinter/__init__.py",line 1883,in __call__
    return self.func(*args)
  File "test.py",line 6,in call_handler
    messageBox.showerror("Title","message")
  File ".pyenv/versions/3.8.0/lib/python3.8/tkinter/messageBox.py",line 94,in showerror
    return _show(title,message,ERROR,OK,**options)
  File ".pyenv/versions/3.8.0/lib/python3.8/tkinter/messageBox.py",line 72,in _show
    res = Message(**options).show()
  File ".pyenv/versions/3.8.0/lib/python3.8/tkinter/commondialog.py",line 44,in show
    s = w.tk.call(self.command,*w._options(self.options))
_tkinter.TclError: bad pad value "2m": must be positive screen distance

如果您提供有关如何进一步解决该问题的任何提示,我将不胜感激。我发现了类似的问题(Error 'bad pad value “2m”: must be positive screen distance' when using tk_messageBox on a wayland display (CentOS) 但不太确定如何在 python3 tkinter 中应用它。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)