簡體   English   中英

Tkinter與Mac OSX

[英]tkinter with mac osx

我有一個與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")

您不要在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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM