1

I have a problem with tkinter.place, why it is not working?

class KafeDaun(tk.Frame):
    def __init__(self, master = None):
        super().__init__(master)
        self.master.title("Kafe Daun-Daun Pacilkom v2.0 ")
        self.master.geometry("500x300")
        self.master.configure(bg="grey")
        self.create_widgets()
        self.pack()

    def create_widgets(self):
        self.btn_buat_pesanan = tk.Button(self, text = "Buat Pesanan", width = 20)
        self.btn_buat_pesanan.place(x = 250, y = 100)

        self.btn_meja = tk.Button(self, text = "Selesai Gunakan Meja", width = 20)

enter image description here

I still get this blank Frame even though already use tkinter.place on btn_buat_pesanan

I expect it to have a button on the exact location, like when using tkinter.pack() or tkinter.grid(). Do you have any suggestion ... ... ... ... ..

acw1668
  • 40,144
  • 5
  • 22
  • 34
conchita
  • 11
  • 1

1 Answers1

1

Try this.

You have to pack the frame like this self.pack(fill="both", expand=True). Because the place did not change the parent size, that's why it didn't visible

import tkinter as tk
class KafeDaun(tk.Frame):
    def __init__(self, master = None):
        super().__init__(master)
        self.master.title("Kafe Daun-Daun Pacilkom v2.0 ")
        self.master.geometry("500x300")
        self.master.configure(bg="grey")
        self.create_widgets()
        self.pack(fill="both", expand=True)

    def create_widgets(self):
        self.btn_buat_pesanan = tk.Button(self, text = "Buat Pesanan", width = 20)
        self.btn_buat_pesanan.place(x = 250, y = 100)

        self.btn_meja = tk.Button(self, text = "Selesai Gunakan Meja", width = 20)
app =tk.Tk()


s = KafeDaun(app)
app.mainloop()

Or you can set the width and height of the frame. super().__init__(master, width=<width>, height=<height>)

codester_09
  • 5,622
  • 2
  • 5
  • 27