tkinter与mac osx

时间:2013-08-24 22:11:21

标签: python macos python-3.x tkinter

我有一个与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")

1 个答案:

答案 0 :(得分:1)

您不会在geometry方法的参数中添加“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