2013-08-24 127 views
0

我有一個與Python 3相關的非常基本的問題。我已經開始學習Python,但有些事情讓我感到困惑。tkinter與mac osx

首先,因爲我想創建一個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

你不單詞「幾何」添加到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 
+0

@馬特我添加了一個新行到我的答案。它看起來像你錯過了'mainloop'調用 – SethMMorton

+0

真棒你修復它! – Matt