关于 python 中的 Tkinter

about Tkinter in python

为什么我不能运行这个?

top.geometry('250*150')

Traceback (most recent call last):
  File "C:\Users\canux\Desktop\myCode\pythonMy\cpp\guitest.py", line 10, in <module>
    top.geometry('250*150')
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1659, in wm_geometry
    return self.tk.call('wm', 'geometry', self._w, newGeometry)
TclError: bad geometry specifier "250*150"

尝试 '250x150' 而不是 '250*150'

如果你看一下 python tkinter 文档,关于几何:

geometry

This is a string of the form widthxheight, where width and height are measured in pixels for most widgets (in characters for widgets displaying text). For example: fred["geometry"] = "200x100".

我认为这是因为 Tkinter 是 Tcl/Tk 的包装器,所以一些约定卡住了。

我以为使用"geometry"方法的格式是这样的:

top.geometry("width × height")

×是乘号。 (您可以使用 Alt + 0215 输入乘号)

但最后我注意到它是:

top.geometry("width x height")

x是x字符不是乘号!!

您可以在这里找到非常有用的信息: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/geometry.html