1

I am working on an app that is supposed to take up the whole screen. When I started, my initial intention was to switch Frames a lot. for example, let's say the user wanted to go to the settings. it would switch from the home Frame and go to the settings Frame.

However, do to some complications with other frames, I found that I would have to add another Frame underneath the first frame. For example, it would have a main Frame underneath the home screen Frame, so that if the user decided to open settings, it would forget the home Frame, and display the settings Frame also on the main Frame.

My problem is that when I added the underneath-everything Frame, things went haywire. the Tk() widget got small, and when I clicked and dragged it bigger, everything was out of proportion. however, it did display the settings when I clicked on the button :D.

here is my code:

self.main = Tk()
self.mainFrame = Frame()
self.mainFrame.pack(expand = True, fill = "both")

self.padding = Canvas(self.mainFrame, width = 1439, height = 
self.CANVAS_HEIGHT)
self.padding.pack()

self.startFrame = Frame(self.mainFrame)
self.startFrame.place(relx = 0.0, rely = 0.0, anchor = "nw")

self.settingsFrame = Frame(self.mainFrame)
self.settingsCanvas = Canvas(self.settingsFrame, bg = "saddleBrown", width = self.CANVAS_WIDTH,  height = self.CANVAS_HEIGHT)
self.settingsCanvas.pack()

self.startFrame.pack_forget()
self.settingsFrame.pack()

once again, when I run the code, everything is out of proportion. If this is not clear, then please tell me.

General Nuisance
  • 211
  • 3
  • 16

1 Answers1

0

Note that you are placing startFrame and then you are pack_forgetting it, but you should place_forget it.

Besides some weirds things in your code, I do not recommend to use place in this case, pack should do the work better (actually I have just used place in a few specific cases).

If you decide to use the pack geometry manager, and if you want your Frames to resize along with the window, you should indicate that you want them to expand and to fill eventually free space in both directions, vertically and horizontally (or y and x):

startFrame.pack(expand=True, fill='both')  # both = x and y

If you want to give a fixed size to a Frame, see this post by Bryan Oakley.

I really recommend you to watch some tutorials or references on the pack geometry manager, because it's really useful, if you want to do something seriously. You can start reading from the Effbot's reference.

Community
  • 1
  • 1
nbro
  • 15,395
  • 32
  • 113
  • 196
  • uh oh... the window stays the same size. I changed the Frame's width and height to fill the screen, but alas, it didn't work. (I apologies if this is a dumb problem, I'm a bit of a blonde with programing:)) – General Nuisance Jan 31 '15 at 02:39
  • ok, I changed it to pack, but it still isn't working. also, I realized, the proportional issues are because the photoImage that is used as the background is being place a bit higher than usual. in fact, some of the stuff I drew on the canvas is being place too high. – General Nuisance Jan 31 '15 at 05:15
  • @oboy Post you current code, and I will try to see if I can help. – nbro Feb 01 '15 at 02:29
  • I just edited my code. let me see... and thank you so much for your help. I'm a complete ding dong. – General Nuisance Feb 01 '15 at 21:59
  • @oboy Your code is part of a class. Please insert all the class. I will try to have a look when I have time, but I do not promise. The only thing I can tell you is to read the documentation about the widgets you are working with. – nbro Feb 01 '15 at 22:18
  • thank you a lot, My dad is helping with it now. it turns out it did work, I just packed it in the wrong place(oops!). thank you so much for your help, I know that you have a job most likely, and that it took some of your time to do this. thanks a lot! – General Nuisance Feb 03 '15 at 04:15