user2975375
user2975375

Reputation: 81

IDLE is crashing on Elementary OS when using rows/columns in Tkinter

So I am learning Tkinter by following a pretty basic tutorial. Here is my file so far:

import sys
from Tkinter import *
# Makes a variable and makes it an instance of the Tk() class
mGui = Tk()

# "500x500" is the dimensions. The other "+100+100" determines where the top left starts
mGui.geometry("500x500+100+100")

# Renames the window to "Learning GUI". Notice it isnt mGui.title = "Learning GUI"
mGui.title("Learning GUI")

# This will pack it automatically
"""mlabel = Label(text = "My Label").pack()"""

# This will pack it later, it's usually better. fg = foreground or text color in this case bg = background
# the Pack function places the object onto the center of the window.
mlabel = Label(text = "My Label 1", fg="red", bg="white")
mlabel.pack()
# Notice how it places it down under the original so they don't overlap.
# mlabel_2 = Label(text = "My Label", fg="red", bg="white")
# mlabel_2.pack()

# Here we are using place and placing it at the designated x and y values.
mlabel_2 = Label(text = "My Label 2", fg="red", bg="white")
mlabel_2.place(x=230, y=250)

#.grid is like creating a grid
mlabel_3 = Label(text = "My Label 3", fg="red", bg="white").grid(row = 0, column = 0)

mlabel_4 = Label(text = "My Label 4", fg="red", bg="white").grid(row = 1, column = 0)

Ignore all my lame comments, but when I run this in IDLE, it just freezes up and I have to use xkill to close it.

With mLabel_4 commented out, IDLE doesn't crash. What's happening?

Upvotes: 0

Views: 112

Answers (1)

I think the main problem is that you're mixing different geometry managers in the same container. While this does sometimes work it is best to avoid it and stick with .pack(), .grid() or .place(). Because tkinter will try to do everything at once and fail more often than not.

Also it is good idea to explicitly give your labels parents. eg:

label = Label(mGui, text = text)
label.grid()

Or else the widget will be placed in the most recently mentioned container by default

Upvotes: 1

Related Questions