Python Forum
Buttons not appearing, first time button making - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Buttons not appearing, first time button making (/thread-15029.html)



Buttons not appearing, first time button making - admiral_hawk - Dec-30-2018

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()



RE: Buttons not appearing, first time button making - Axel_Erfurt - Dec-30-2018

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()



RE: Buttons not appearing, first time button making - woooee - Dec-30-2018

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() 



RE: Buttons not appearing, first time button making - admiral_hawk - Dec-30-2018

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!


RE: Buttons not appearing, first time button making - woooee - Dec-31-2018

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.


RE: Buttons not appearing, first time button making - admiral_hawk - Dec-31-2018

Thanks! That worked!