Python Forum
[Tkinter] program doesn't run. - 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: [Tkinter] program doesn't run. (/thread-1603.html)



program doesn't run. - Doug - Jan-15-2017

Was watching a tutorial on youtube on how to use OOP in building GUI, but can not run identical code myself.
Error: "in line 27 app = Application() TypeError: __init__() missing 1 required positional argument: 'master'"
anybody could explain? Thank you!

from tkinter import *

class Application(Frame):

    def __init__(self, master):
        Frame.__init__(self.master)
        self.grid()
        self.create_widgets()

    def create_widgets(self):

        self.button1 = Button(self, text ="1")
        self.button1.grid()

        self.button2 = Button(self)
        self.button2.grid()
        self.button2.configure(text = "This will show up text")

        self.button3 = Button(self)
        self.button3.grid()
        self.button3["text"] = "This will also show text"
        
root = Tk()
root.title("Lazy Buttons")
root.geometry("200x85")

app = Application()
app.create_widgets()

root.mainloop()



RE: program doesn't run. - Larz60+ - Jan-15-2017

You need to supply a master window reference
app = Application(root)



RE: program doesn't run. - Doug - Jan-15-2017

(Jan-15-2017, 07:41 PM)Larz60+ Wrote: [Tkinter] program doesn't run.
(Jan-15-2017, 07:41 PM)Larz60+ Wrote: You need to supply a master window reference
 app = Application(root) 
It is working now! Many thanks!