Python Forum
Buttons not appearing, first time button making
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Buttons not appearing, first time button making
#1
Hi, I have been watching python tutorials and finally got to GUI and have been trying to figure out buttons, I typed in the code as instructed however when the window opens there is still no quit button. Been looking at this for a while now and can't seem to figure out whats wrong. Am I perhaps missing a tkinter file? Here is the code:

from tkinter import *

class Window (Frame) :

    def __init__(self, master = None) :
        Frame.__init__(self, master)
        self.master = master
        self.init_window()

def init_window(self) :
    self.master.title("GUI")
    self.pack(fill=BOTH, expand=1)
    quitButton = Button(self, text="Quit")
    quitButton.place(x=0, y=0)

root = Tk()
root.geometry("400x300")
app = Window(root)
root.mainloop()
Reply
#2
the indentation is wrong

try

from tkinter import *
 
class Window (Frame) :
 
    def __init__(self, master = None) :
        Frame.__init__(self, master)
        self.master = master
        self.init_window()
 
    def init_window(self) :
        self.master.title("GUI")
        self.pack(fill=BOTH, expand=1)
        quitButton = Button(self, text="Quit")
        quitButton.place(x=0, y=0)
 
root = Tk()
root.geometry("400x300")
app = Window(root)
root.mainloop()
Reply
#3
Your code, cleaned up, so it actually works (find another tutorial that doesn't include the unnecessary crap, and explains things, like http://effbot.org/tkinterbook/button.htm or one of these https://wiki.python.org/moin/TkInter ). Note that the button doesn't do anything because there is no "command=" provided.
from tkinter import *

class Window() :
     def __init__(self, master = None) :
        self.master = master
        self.init_window()

     def init_window(self):
        self.master.title("GUI")
        quitButton = Button(self.master, text="Quit", bg="red")
        quitButton.grid()

root = Tk()
root.geometry("400x300")
app = Window(root)
root.mainloop() 
Reply
#4
Thanks for the assistance! I didn't even notice the indentation lol, however it the quit button still isn't showing up with the window.

The cleaned up version also still didn't seem to bring the quit button up but I appreciate the assistance very much and am looking into those tutorials!
Reply
#5
I changed the background of the button to red to make it obvious to you. If you still don't see the button, post the new code that you are using.
Reply
#6
Thanks! That worked!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter: An image and label are not appearing. emont 7 397 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  My Background Image Is Not Appearing (Python Tkinter) HailyMary 2 3,972 Mar-14-2023, 06:13 PM
Last Post: deanhystad
  Figure Gets Larger Every time I click a show button joshuagreineder 2 1,266 Aug-11-2022, 06:25 AM
Last Post: chinky
  [Tkinter] Scrollable buttons with an add/delete button Clich3 5 3,331 Jun-16-2022, 07:19 PM
Last Post: rob101
  [Tkinter] Command button, then more command buttons Heyjoe 4 2,817 Aug-08-2020, 11:28 AM
Last Post: Yoriz
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 4,947 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Tkinter widgets not appearing (3.x) RSAngryfiend 1 9,192 Jul-05-2017, 09:13 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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