Python Forum
Creating a frame with 4 command buttons
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a frame with 4 command buttons
#1
Hello python users:

The following code is to create a frame with four command buttons. It does this. However, before it creates the frame with four command buttons, it creates a frame with no buttons. Why does it create the frame with no buttons?


import tkinter as tk
myfont = "Helvitica 30"
mybg = "lightskyblue"


class Main:

    def __init__(self, root):
        self.root = tk.Tk()
        self.root.geometry("500x500")
        self.createfstframe()

    def createfstframe(self):
        fstframe = tk.Frame(root)
        fstframe.pack(padx=100, pady=100)
        self.Hellobn=tk.Button(fstframe,text = "Hello", bg = mybg, font = myfont)
        self.Hellobn.pack(fill = tk.BOTH, expand = 1)
        self.Howyoubn = tk.Button(fstframe, text="How are you? ",bg = mybg ,font = myfont)
        self.Howyoubn.pack(fill = tk.BOTH, expand = 1)
        self.clickherebn = tk.Button(fstframe, text = "Click here to start", bg = "deepskyblue",font = myfont)
        self.clickherebn.pack(fill = tk.BOTH, expand = 1)
        self.quitbn = tk.Button(fstframe,text = "Quit", font = myfont, bg = "red", command = fstframe.quit)
        self.quitbn.pack(fill = tk.BOTH, expand = 1)


root = tk.Tk()
b=Main(root)
root.mainloop()
Reply


Messages In This Thread
Creating a frame with 4 command buttons - by Heyjoe - Aug-20-2020, 02:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Programmatically creating buttons that remember their positions Clunk_Head 6 1,448 Jun-22-2023, 02:51 PM
Last Post: deanhystad
  [Tkinter] Command button, then more command buttons Heyjoe 4 2,971 Aug-08-2020, 11:28 AM
Last Post: Yoriz
  [Tkinter] Creation of Buttons with Shared Command Inside Class MulliganAgain 1 1,751 Jul-08-2020, 06:22 PM
Last Post: Yoriz
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 9,168 Sep-30-2019, 07:30 AM
Last Post: Maksim
  [Tkinter] How to add an argument to a buttons command call petterg 2 3,188 Jun-20-2019, 09:05 PM
Last Post: petterg
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 11,325 Apr-18-2019, 05:36 PM
Last Post: atlass218
  [Tkinter] Frame size only works if frame is empty(Solved) Tuck12173 7 6,592 Jan-29-2018, 10:44 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020