0

I'm having a problem with dealer_score_no.grid_propagate(0) and player_score_no.grid_propagate(0) which are the scores for the dealer and player respectively. I experimented with resizing the font, or removing the score labels during the game and what I get is bouncing rows all around. I tried configuring the rows' weights, the problem is I don't really know which weights I need. I'm guessing I'm doing something wrong. I found a way around it by just ditching the resizing, and simply removing the textvariables assigned to them (badly named, I know) and resetting the text to an empty string, which worked fine. No more bouncing rows. But I still want to know how to use the weight and grid_propagate(0) options.

felt = tkinter.Frame(mainWindow,
                     bg=FELT_COLOR)  # , relief='groove', borderwidth='3')
felt.grid(row=1, column=0, sticky='wens', columnspan=3)

# Dealer cards and score area
dealer_score_label = tkinter.IntVar()
dealer_card_frame = tkinter.Frame(felt, height=card_frame_height, width=800,
                                  background=FELT_COLOR, bd=0, relief="groove")
dealer_card_frame.grid(row=0, column=1, columnspan=3, padx=400, sticky='w')
dealer_score_obj = tkinter.Label(felt, text='',
                                 background=FELT_COLOR, fg=themes[theme]['card_frame_lbl_fg'])
dealer_score_obj.grid(row=1, column=1, columnspan=3, sticky='n', pady=4)
dealer_score_obj.place()
dealer_score_no = tkinter.Label(felt,
                                font=font.Font(size=18), background=FELT_COLOR,
                                fg=themes[theme]['card_frame_lbl_fg'])
dealer_score_no.grid(row=2, column=1, columnspan=3, sticky='n', pady=8)
dealer_score_no.grid_propagate(0)

# Player's score area
player_score_label = tkinter.IntVar()
player_score_obj = tkinter.Label(felt, text='',
                                 background=FELT_COLOR, fg=themes[theme]['card_frame_lbl_fg'])
player_score_obj.grid(row=3, column=1, columnspan=3, sticky='sew', pady=(200, 0))
player_score_no = tkinter.Label(felt,
                                font=font.Font(size=18), background=FELT_COLOR,
                                fg=themes[theme]['card_frame_lbl_fg'])
player_score_no.grid(row=4, column=1, columnspan=3, sticky='n', pady=8)
player_score_no.grid_propagate(0)

player_card_frame = tkinter.Frame(felt, height=card_frame_height, width=800,
                                  background=FELT_COLOR, bd=0, relief="groove")
player_card_frame.grid(row=5, column=1, columnspan=3, padx=400, sticky='sw')

betting_frame = tkinter.Frame(felt, height=100, bg=FELT_COLOR, width=int(mainWindow.winfo_screenwidth() * 0.66))
betting_frame.grid(row=6, column=1, columnspan=3, sticky='ew')
felt.config(height=felt.winfo_reqheight())```

[![This is how it looks like.][1]][1]


  [1]: https://i.stack.imgur.com/Ae4pt.png
vl3005
  • 45
  • 4
  • 1
    `dealer_score_no.grid_propagate(0)` you need to adress `grid_propagate()` to a master *window or frame* not to a label. – Thingamabobs Oct 03 '20 at 18:20
  • 1
    Also take a look at this answer here https://stackoverflow.com/questions/45847313/what-does-weight-do-in-tkinter/45850468#45850468 – Thingamabobs Oct 03 '20 at 18:25
  • Ok, good to know. So I assume the only way to control this, then, is to build a layout of frames with `grid_propagate(0)` for every label that changes size, or needs to disappear. otherwise, when it does that, it will cause everything beneath it, to bounce up. Did I get it right? – vl3005 Oct 04 '20 at 04:34
  • It really depends how you build your GUI and how the whole program reacts to empty space. I highly recommend this answer that I wrote here. You could have a minsize for your application for example. Or using weight to compensate it. You have to understand that this is a bit like an architecture. https://stackoverflow.com/a/63536506/13629335 – Thingamabobs Oct 04 '20 at 06:32
  • Some hints are in the code, like the yellow frame in this example is with grid and I used weight on the empty column to have a left and right effect like with pack. – Thingamabobs Oct 04 '20 at 06:40

1 Answers1

1

grid_propagate only matters if the widget you call it on has children. If you call it on a widget with no children it will have no effect.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685