#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Python 3 Tkinter module


    I'm trying to create a frame in Python 3's Tkinter module and have a button appear but it doesn't seem to work. Here's my code:

    Code:
    from tkinter import*;
    
    root = Tk();
    root.title("Lazy Buttons");
    root.geometry("200x85");
    
    class Application(Frame):
        def __init__(self,master):
            Frame.__init__(self,master);
            self.grid;
            self.create_widget();
        def create_widget(self):
            self.bttn = Button(self,"text"="I do nothing!");
            self.bttn.grid();
    
    app = Application(root);
    root.mainloop();
    Any ideas on how to fix it?

    I was already able to get to to run by directly invoking the Frame constructor without defining a class. The problem seems to arise when I try to define a class for my Frame object.

    Thanks!

    BiP
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    83
    Rep Power
    39
    The problems have nothing to do with the fact that you're defining your own class. The problems are that you're using a string as a keyword argument on line 13 and that you don't call the grid method in __init__ ("self.grid" doesn't call the method - you need "()" to call a method).

    Comments on this post

    • jamespayne agrees
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0
    Thanks!

    BiP
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,966
    Rep Power
    481
    In python as in gawk, semi-colon separates statements.

    In c, `;' terminates statements.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo