Tkinter ve place metodu

Merhaba, tkinter öğrenme aşamasında şöyle bir görsel elde etmeye çalışıyorum:

Ancak yazdığım koddaki hatayı bir türlü bulamadım. Yeşil ve sarı frameler üst üste geliyor.

import tkinter as tk
from tkinter import ttk

class App(tk.Tk):
    def __init__(self, size, title):
        
        # main setup
        super().__init__()
        self.geometry(f'{size[0]}x{size[1]}')
        self.title(title)
        
        # widgets
        self.one = One(self)
        self.two = Two(self)
        self.three = Three(self)
        self.four = Four(self)
        
        # run
        self.mainloop()
        
class One(tk.Frame):
    def __init__(self, parent):
        super().__init__()
        tk.Label(self, background='red').pack(expand=True, fill='both')
        self.place(x = 0, y = 0, relwidth = 0.3, relheight = 0.3)


class Two(tk.Frame):
    def __init__(self, parent):
        super().__init__()
        tk.Label(self, background='blue').pack(expand=True, fill='both')
        self.place(relx = 0.3, y = 0, relwidth = 0.7, relheight = 0.3)


class Three(tk.Frame):
    def __init__(self, parent):
        super().__init__()
        tk.Label(self, background='Green').pack(expand=True, fill='both')
        self.place(relx = 0, y = 0.3, relwidth = 0.3, relheight = 0.7)


class Four(tk.Frame):
    def __init__(self, parent):
        super().__init__()
        tk.Label(self, background='Yellow').pack(expand=True, fill='both')
        self.place(relx = 0.3, y = 0.3, relwidth = 0.7, relheight = 0.7)


App(title='Class based app', size=(600,600))

Kendi kendimi doğrulamış olayım. place metodundaki relx ve rely lerin bazıları y olarak kalmış. Düzeltince istediğim sonucu aldım.

import tkinter as tk
from tkinter import ttk

class App(tk.Tk):
    def __init__(self, size, title):
        
        # main setup
        super().__init__()
        self.geometry(f'{size[0]}x{size[1]}')
        self.title(title)
        
        # widgets
        self.one = One(self)
        self.two = Two(self)
        self.three = Three(self)
        self.four = Four(self)
        
        # run
        self.mainloop()
        
class One(tk.Frame):
    def __init__(self, parent):
        super().__init__()
        tk.Label(self, background='red').pack(expand=True, fill='both')
        self.place(relx = 0, rely = 0, relwidth = 0.3, relheight = 0.3)


class Two(tk.Frame):
    def __init__(self, parent):
        super().__init__()
        tk.Label(self, background='blue').pack(expand=True, fill='both')
        self.place(relx = 0.3, rely = 0, relwidth = 0.7, relheight = 0.3)


class Three(tk.Frame):
    def __init__(self, parent):
        super().__init__()
        tk.Label(self, background='Green').pack(expand=True, fill='both')
        self.place(relx = 0, rely = 0.3, relwidth = 0.3, relheight = 0.7)


class Four(tk.Frame):
    def __init__(self, parent):
        super().__init__()
        tk.Label(self, background='Yellow').pack(expand=True, fill='both')
        self.place(relx = 0.3, rely = 0.3, relwidth = 0.7, relheight = 0.7)


App(title='Class based app', size=(600,600))
1 Beğeni