Max Powers
Max Powers

Reputation: 1179

tkinter with mac osx

I have a very basic question related to Python 3. I have started to learn Python but some things are confusing me.

First off, since I want to create a python script that is a GUI, I have imported the tkinter module. The code works in IDLE, but never works when I run it from the terminal. Whenever I run the script from the terminal, I see this traceback error:

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"

Basically, what I am trying to do is create a Python GUI script, save it, and execute it via my terminal whenever I need it.

Here is the code:

#!/usr/bin/env python3

import sys
from tkinter import *



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

Upvotes: 0

Views: 3720

Answers (1)

SethMMorton
SethMMorton

Reputation: 48725

You don't add the word "geometry" to the argument of the geometry method. Try this instead:

#!/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()

Here are some other GUI configurations that you may need in the future (I personally had trouble finding/applying all the information):

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

Upvotes: 1

Related Questions