Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I'm learning Python GUI programming with tkinter. I needed to put an edge in my root window utilizing the grid geometry manager, indicate a height, and have the frame grow to the full width of the root window. I attempted to do this utilizing the tacky alternatives however this doesn't create the ideal outcome. How would I cause the frame to grow to the full width of the window without physically indicating the width?

Code:

import tkinter

import tkinter.ttk

win = tkinter.Tk()

win.geometry('600x600')

frame = tkinter.Frame(win, height=300)

frame.configure(bg='red')

frame.grid(column=0, sticky=tkinter.E + tkinter.W)

win.mainloop()

1 Answer

0 votes
by (26.4k points)

Try the below code (Make sure that call to grid_columnconfigure is on win, which is actually the parent of your frame gadget):

import tkinter

import tkinter.ttk

win = tkinter.Tk()

win.geometry('600x600')

frame = tkinter.Frame(win, bg='red', height=300)

frame.grid(row=0, column=0, sticky='ew')

win.grid_columnconfigure(0,weight=1)

win.mainloop()

Are you pretty much interested to learn python in detail? Come and join the python training course to gain more knowledge.

To know more about this you can have a look at the following video tutorial:-

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...