Hello Python Users:
The following code displays a command button "Click here to start". This command button is supposed to run the sa function. The sa function is supposed to display a new frame and command button and also print hello. It prints hello but does not display the command button or frame. Why does the command button not display?
The following code displays a command button "Click here to start". This command button is supposed to run the sa function. The sa function is supposed to display a new frame and command button and also print hello. It prints hello but does not display the command button or frame. Why does the command button not display?
import tkinter as tk myfont = "Helvitica 30" mybg = "lightskyblue" class Main: def __init__(self, root): self.root = root 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, command = self.sa) 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) def sa(self): mnframe = tk.Frame(root) mnframe.pack(padx=100, pady=100) self.mybn = tk.Button(mnframe, text="mybutton", font=myfont, bg="red") self.mybn.pack(fill=tk.BOTH, expand=1) print("Hello") root = tk.Tk() b=Main(root) root.mainloop()