Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8765891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:24:15+00:00 2026-06-13T16:24:15+00:00

I am trying to create Buttons in Python with classes, but when running it

  • 0

I am trying to create Buttons in Python with classes, but when running it the buttons do not appear. Following is my code

#Button_2
#Using Classes

from Tkinter import * 

class Application(Frame):
    """A GUI application with three button"""

    def _init_(self, master):
        """ Initialise the Frame. """
        Frame._init_(self, master)
        self.grid()
        self.create_widgets()

    def create_widgets(self):
        #"""Create three buttons"""
        #Create first buttom
        self.btn1 = Button(self, text = "I do nothing")
        self.btn1.grid()

        #Create second button
        self.btn2 = Button(self)
        self.btn2.grid()
        self.btn2.configure(text = "T do nothing as well")

        #Create third button
        self.btn3 = Button(self)
        self.btn3.grid()    
        self.btn3.configure(text = "I do nothing as well as well")

    root = Tk()
    root.title("Lazy Button 2")
    root.geometry("500x500")
    app = Application(root)

    root.mainloop()

Any help would be appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:24:17+00:00Added an answer on June 13, 2026 at 4:24 pm

    OK, first problem is that you have declared your following code:

    root = Tk()
    root.title("Lazy Button 2")
    root.geometry("500x500")
    app = Application(root)
    
    root.mainloop()code here
    

    inside the class itself. It should be outside, so this an indentation problem (maybe stackoverflow problem with indents?).

    secondly I simplified the code to get it to run

    from Tkinter import * 
    
    class Application(Frame):
          """A GUI application with three button"""
    
         #create a class variable from the root (master):called by the constructor
         def _init_(self, master):
              self.master = master
    
         #simple button construction
         # create a button with chosen arguments
         # pack it after the creation not in the middle or before
    
         def create_widgets(self):
              #"""Create three buttons"""
              #Create first button
              btn1 = Button(self.master, text = "I do nothing")
              btn1.pack()
    
              #Create second button
              btn2 = Button(self.master, text = "T do nothing as well")
              btn2.pack()
    
             #Create third button
             btn3=Button(self.master, text = "I do nothing as well as well")
             btn3.pack()
    
      #must be outside class definition but probably due to stackoverlow
      root = Tk()
      root.title("Lazy Button 2")
      root.geometry("500x500")
      app = Application(root)
      #call the method
      app.create_widgets()
      root.mainloop()
    

    This is a starting point and definitely works as proven below:

    enter image description here

    You can probablty muck around with the grid() instead of pack and call the method from the def init constructor. Hope it helps.

    This calling method also works:

    root = Tk()
    root.title("Lazy Button 2")
    root.geometry("500x500")
    app = Application(root).create_widgets()  #creates and invokes
    root.mainloop()
    

    My final try also works:

    def __init__(self,master):
        self.master = master
        self.create_widgets()
    

    followed by:

    root = Tk()
    root.title("Lazy Button 2")
    root.geometry("500x500")
    app = Application(root)
    root.mainloop()
    

    enter image description here

    The final code:

    from Tkinter import * 
    
    class Application(Frame):
    """A GUI application with three button"""
    
    def __init__(self,master):
        self.master = master
        self.create_widgets()
    
    
    
    def create_widgets(self):
        #"""Create three buttons"""
        #Create first buttom
        btn1 = Button(self.master, text = "I do nothing")
        btn1.pack()
    
        #Create second button
        btn2 = Button(self.master, text = "T do nothing as well")
        btn2.pack()
    
        #Create third button
        btn3=Button(self.master, text = "I do nothing as well as well")
        btn3.pack()
    
    root = Tk()
    root.title("Lazy Button 2")
    root.geometry("500x500")
    app = Application(root)
    root.mainloop()
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create css buttons by using the following html markup: <a href=access.php
I'm trying to create a GUI in Python using the Tkinter module, and part
I'm new to Python and I'm trying to create a simple GUI using Tkinter.
I'm trying to create a Window using PyGTK that has dynamically created radio buttons
I'm trying to create Command Buttons dynamically, but clicking the button in question doesn't
I'm trying create a gui using Tkinter that grabs a username and password and
I'm trying to create a python 2.7 tkinter module which uses scale widget data
I'm trying to create a text widget in Tkinter (for Python) whose font size
I'm trying to write a python code which create and initialize n timers in
Hey, I'm trying to create Like Buttons for Facebook Photos, but can't figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.