Python - Tkinter Grid

Asked

Viewed 276 times

-3

How can I build this layout using Grid? The gray rectangle used place, however, I would like to know how to get the same result using Grid in all elements.

Layout

from tkinter import *


class Main():
    def __init__(self, master = None):
        self.topFrame = Frame(master, width = 1200 , height = 30 , bg = "blue")
        self.topFrame.grid(row = 0, column = 0)

        self.middleFrame = Frame(master, width = 1200, height = 600 , bg = "cyan")
        self.middleFrame.grid(row = 1, column = 0)

        self.bottomFrame = Frame(master, width = 1200, height = 70, bg = "yellow")
        self.bottomFrame.grid(row = 2, column = 0)


        self.leftFrame = Frame(self.middleFrame, width = 150, height = 600, bg = "gray")
        self.leftFrame.place(x = 0 , y = 0)







root = Tk()

w = 1200
h = 700

wScreen = root.winfo_screenwidth()
hScreen = root.winfo_screenheight()

x = (wScreen/2) - (w/2)
y = (hScreen/2) - (h/2)





root.geometry('%dx%d+%d+%d' % (w, h, x, y))
root.title("Sistema com Tkinter")
root.iconbitmap(r'icon/admin.ico')

Main(root)
root.mainloop()

1 answer

0

ola, to achieve the effect just put one more frame, using grid you should look for nesting frames

from tkinter import *


class Main():
    def __init__(self, master = None):
        self.topFrame = Frame(master, width = 1200 , height = 30 , bg = "blue")
        self.topFrame.grid(row = 0, column = 0)

        self.middleFrame = Frame(master, width = 1200, height = 600)
        self.middleFrame.grid(row = 1, column = 0)

        self.bottomFrame = Frame(master, width = 1200, height = 70, bg = "yellow")
        self.bottomFrame.grid(row = 2, column = 0)


        self.leftFrame = Frame(self.middleFrame, width = 150, height = 600, bg = "gray")
        self.leftFrame.grid(row = 0 , column = 0)

        self.rightFrame = Frame(self.middleFrame, width = 1050, height = 600, bg = "cyan")
        self.rightFrame.grid(row = 0 , column = 1)


###

root = Tk()

w = 1200
h = 700

wScreen = root.winfo_screenwidth()
hScreen = root.winfo_screenheight()

x = (wScreen/2) - (w/2)
y = (hScreen/2) - (h/2)

root.geometry('%dx%d+%d+%d' % (w, h, x, y))
root.title("Sistema com Tkinter")
root.iconbitmap(r'icon/admin.ico')

Main(root)
  • Thank you. Solved!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.