执行下面的代码时在python中获取错误的几何体说明符

时间:2017-11-15 04:52:51

标签: python tkinter

尝试以下代码时:

import tkinter

print(tkinter.TkVersion)

print(tkinter.TclVersion)

mainWindow = tkinter.Tk()

mainWindow.title("Hello Python")

mainWindow.geometry("1200X1024")

mainWindow.mainloop()

我收到错误:

 Traceback (most recent call last):
   File "C:\Users\Satya\IdeaProjects\GUO_python\tkinter1.py", line 11, in <module>
     mainWindow.geometry("1200X1024")
   File "C:\Users\Satya\Anaconda3\lib\tkinter\__init__.py", line 1835, in wm_geometry
     return self.tk.call('wm', 'geometry', self._w, newGeometry)
 _tkinter.TclError: bad geometry specifier "1200X1024"

https://i.stack.imgur.com/EJyn6.jpg

3 个答案:

答案 0 :(得分:3)

传递给几何体的参数不太正确。

您已撰写1200X1024 - 但X需要小写。

尝试mainWindow.geometry("1200x1024")

答案 1 :(得分:1)

你也可以使用添加&#34; +&#34;指定您希望窗口在屏幕上的位置

  

import tkinter print(tkinter.TkVersion) print(tkinter.TclVersion) mainWindow = tkinter.Tk() mainWindow.title("Hello Python") mainWindow.geometry("1200x1024") # use "x" instead of " X" mainWindow.mainloop()

state('small', style({position: 'relative', width: '50%'})),
state('large', style({
    transform: 'translateY(-150px)',
    position: 'absolute',
    width: '100%'
})),
transition('small => large', animate('600ms ease', keyframes([
    style({position: 'absolute', width: '100%', offset: 0}),
    style({transform: 'translateY(-150px)',  offset: 1.0}),
]))),
transition('large => small', animate('600ms ease', keyframes([
    style({transform: 'translateY(-150px)',  offset: 0}),
    style({width: '50%', right: 0, offset: 1.0}),
])))

答案 2 :(得分:0)

此外,如果您设置1200x1024(而非“X”)以使您的窗口占据整个屏幕,则可以使用mainWindow.state('zoomed')