python - How to stop automatic resizing of frames -


i have 3 frames, when new label appears frames automatically readjust new size. how stop readjustment , have size of each frame set , immutable.

#import tkinter make gui tkinter import * tkinter import ttk import codecs  #program results when user attempts log in def login(*args):     file = open("rot13.txt", "r")     lines = file.readlines()     uname = user.get()     pword = pw.get()      in lines:         x = i.split()         if codecs.encode(uname,'rot13') == x[0] , codecs.encode(pword,'rot13') == x[1]:             result.set("successful")             break;         else:             result.set("access denied")  root = tk() root.title("login")  #configures column , row settings , sets padding mainframe = ttk.frame(root, padding="3 3 12 12") mainframe['borderwidth'] = 5 mainframe['relief'] = "solid" mainframe.grid(column=1, row=1, columnspan=3, rowspan=2) mainframe.columnconfigure(0, weight=1) mainframe.rowconfigure(0, weight=1)  mainframe2 = ttk.frame(root, padding="3 3 12 12") mainframe2['borderwidth'] = 5 mainframe2['relief'] = "solid" mainframe2.grid(column=1, row=3, columnspan=1, rowspan=3) mainframe2.columnconfigure(0, weight=1) mainframe2.rowconfigure(0, weight=1)  mainframe3 = ttk.frame(root, padding="3 3 12 12") mainframe3['borderwidth'] = 5 mainframe3['relief'] = "solid" mainframe3.grid(column=2, row=5) mainframe3.columnconfigure(0, weight=1) mainframe3.rowconfigure(0, weight=1)  #anchors widgets user = stringvar() pw = stringvar() result = stringvar()  #asks user input user_entry = ttk.entry(mainframe, width=20, textvariable=user) user_entry.grid(column=2, row=1, sticky=(w, e))  pw_entry = ttk.entry(mainframe, width=20, textvariable=pw) pw_entry.grid(column=2, row=2, sticky=(w, e))   #labels make user-friendly , able understand ttk.label(mainframe, text="username ").grid(column=1, row=1, sticky=w) ttk.label(mainframe, text="password ").grid(column=1, row=2, sticky=w) ttk.label(mainframe2, text="").grid(column=1, row=3, sticky=w) ttk.label(mainframe2, text="result").grid(column=1, row=4, sticky=w) ttk.label(mainframe2, text="").grid(column=1, row=5, sticky=w)  #button log in ttk.button(mainframe3, text="login", command=login).grid(column=3, row=5, sticky=(w,e))  #makes spot put in result ttk.label(mainframe2, textvariable=result).grid(column=2, row=4, sticky=(w, e)) #opens item selected , allows enter username without having click user_entry.focus() #runs calculate if click enter root.bind('<return>', login) root.mainloop() 

here before , after picture of results:

beginning

and after result appears happens

as can see frames change sizes after program runs course. how stop re-size , stick predetermined size?

the simplest solution in specific case give label text fixed width. when specify fixed width label, tkinter it's best honor width (though lot depends on how place on screen pack, place or grid).

ttk.label(..., width=12).grid(...) 

another solution turn off geometry propagation, means you're responsible giving frame explicit width , height:

mainframe2 = ttk.frame(..., width=200, height=100) ... mainframe2.grid_propagate(false) 

i not recommend turning geometry propagation off. tkinter @ computing right size widgets, , results in poor behavior if change fonts, screen resolutions, or root window sizes.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -