0

我有一个与 Python 3 相关的非常基本的问题。我已经开始学习 Python,但有些事情让我感到困惑。

首先,因为我想创建一个作为 GUI 的 python 脚本,所以我已经导入了tkinter模块。该代码在 IDLE 中工作,但当我从终端运行它时永远不会工作。每当我从终端运行脚本时,我都会看到以下回溯错误:

Traceback (most recent call last):
  File "test1.py", line 9, in <module>
    mGui.geometry("geometry 480x480") 
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/tkinter/
__init__.py", line 1607, in wm_geometry
    return self.tk.call('wm', 'geometry', self._w, newGeometry)
_tkinter.TclError: bad geometry specifier "geometry 480x480"

基本上,我要做的是创建一个 Python GUI 脚本,保存它,并在需要时通过我的终端执行它。

这是代码:

#!/usr/bin/env python3

import sys
from tkinter import *



mGui =Tk("")
mGui.geometry("geometry 480x480") 
mGui.title("Leilani spelling test")
4

1 回答 1

1

您不会将“几何”一词添加到geometry方法的参数中。试试这个:

#!/usr/bin/env python3

import sys
from tkinter import *

mGui =Tk("")
mGui.geometry("480x480") 
mGui.title("Leilani spelling test")
# You'll want to add this to enter the event loop that causes the window to be shown
mGui.mainloop()

以下是您将来可能需要的其他一些 GUI 配置(我个人在查找/应用所有信息时遇到了麻烦):

mGui.overrideredirect(1) # Remove shadow & drag bar. Note: Must be used before wm calls otherwise these will be removed.
mGui.call("wm", "attributes", ".", "-topmost", "true") # Always keep window on top of others
mGui.geometry("100x100+500+500") # Set offset from top-left corner of screen as well as size
mGui.call("wm", "attributes", ".", "-transparent", "true") # Remove shadow from window
mGui.call("wm", "attributes", ".", "-fullscreen", "true") # Fullscreen mode
mGui.call("wm", "attributes", ".", "-alpha", "0.9") # Window Opacity 0.0-1.0
于 2013-08-24T22:16:20.897 回答