Reputation: 35
I'm new to python and I'm designing a simple GUI for a tile based game using Tkinter. I've recently found out about PyGame and I may consider using this, but for now I'd like to diagnose this error.
Here's my problem.
The root window holds two frames - a frame for the tiles and a frame for the history of the game.
The frame for the tiles consists of another 11x7 frames that have different coloured backgrounds and the frame for the game history will hold a simple Text widget.
I construct the frames in the root window like so:
# Create the root window
root = tk.Tk()
root.title("The Downfall of Pompeii")
root.geometry("1025x525")
root.configure(background="red")
# root.resizable(False, False)
board_frame = tk.Frame(root, width=825, height=525)
information_frame = tk.Frame(root, width=200, height=525)
board_frame.grid(row=0, column=0),
information_frame.grid(row=0, column=1)
This works as expected: game window
But, when I add the Text widget to the information frame, like this:
information_area = tk.Text(information_frame, width=200, height=525)
information_area.grid(row=0, column=0)
This happens: tiles disappear
The text widget is added and works as expected, but it's now interfered with all the frames(tiles) I added to board_frame. The frames are added piece by piece and then aligned using this for loop:
# Align all frames
for i in range(rows):
for j in range(cols):
frames[i][j].grid(row=i, column=j, columnspan=1, sticky="nsew")
As you can see, each index in frames holds a reference to a frame.
So, my question is, why has adding the Text widget interfered with the tiles when I've placed them in two completely different frames?
Upvotes: 2
Views: 441
Reputation: 7176
For a text widget width and heigth is in numbers of caracters and text lines. width=200, height=525
will be 200 characters wide and 525 lines high. The tiles disappear because the text widget "pushes" them down in the frame.
Try width=10, height=10
and the text widget will re-appear.
Upvotes: 1