python - Set the same width to an entry and text tkinter label -


i put entry , text label 1 under other , same width.

here code :

from tkinter import *   root = tk()  title = stringvar() title_entry = entry(root, textvariable=title, width=30) title_entry.pack()   content_text = text(root, width=30) content_text.pack()  root.mainloop() 

but 2 widgets don't have same width. idea solve ?

the widgets different sizes because have different default fonts. if have same fonts , same widths, should have same natural width. however, actual width can affected how placed in window, , there reasons use different fonts these widgets.

the simplest solution in case have each widget fill container in x axis. makes sure that, regardless of natural width, expand fill window edge edge:

title.pack(fill="x") content_text.pack(fill="x") 

if these 2 widgets you'll want go step further , specify additional options proper resize behavior:

title.pack(fill="x") content_text.pack(fill="both", expand=true) 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -