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

  • SEARCH
  • Home
  • 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 8940147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:58:21+00:00 2026-06-15T10:58:21+00:00

from tkinter import * class GameBoard(Frame): def __init__(self): top = Toplevel() Frame.__init__(self) self.master.title(test) self.grid()

  • 0
from tkinter import *

class GameBoard(Frame):
  def __init__(self):
    top = Toplevel()
    Frame.__init__(self)
    self.master.title("test")
    self.grid()
    #button frame
    self.__buttonPane = Frame(self)
    self.__buttonPane.grid()
    #buttons
    self.__buttonA1 = Button(self.__buttonPane,text = "A1",command = self._test("A"))
    self.__buttonA1.grid()

 def _test(self,test):
    if self.__buttonA1["state"] == NORMAL:
       print(test)


def main():
  GameBoard().mainloop()

main()

This code will not work due to the variable and if I remove the variable test and make it

from tkinter import *

class GameBoard(Frame):
  def __init__(self):
    top = Toplevel()
    Frame.__init__(self)
    self.master.title("test")
    self.grid()
    #button frame
    self.__buttonPane = Frame(self)
    self.__buttonPane.grid()
    #buttons
    self.__buttonA1 = Button(self.__buttonPane,text = "A1",command = self._test)
    self.__buttonA1.grid()

  def _test(self):
    if self.__buttonA1["state"] == NORMAL:
      print("hi")

def main():
  GameBoard().mainloop()

main()

How would I fix my code so it would allow for input of a variable?
This is just a test I am doing so I can make it work in a much bigger code.

  • 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-15T10:58:22+00:00Added an answer on June 15, 2026 at 10:58 am

    When you specify command = self._test, self._test is a function that will be called. self._test("A") is not a function, it’s a call to a function (that returns None because there’s no return statement in the definition).

    You can write ‘a function that calls self._test("A") as either lambda: self._test("A"), or functools.partial(self._test, "A"), or explicitly in GameBoard.__init__:

    def _f():
        self._test("A")
    self.__buttonA1 = Button(self.__buttonPane,text = "A1",command = _f)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from tkinter import * class GameBoard(Frame): def __init__(self): Frame.__init__(self) self.master.title(test) self.grid() #button frame self.__buttonPane
from Tkinter import * class StatusBar(Frame): def __init__(self, master): Frame.__init__(self, master) self.label = Label(self,
from TKinter import * class Ui(Frame): def __init__(self) Frame.__init__(self, None) self.grid() bquit=Button(self, text=Quit, command=self.quit_pressed)
from Tkinter import * class Output: def __init__(self,master): self.u=Text(master,width=40) self.u.grid(row=0,column=0) self.v=Button(master,text=Add text,command=Write) self.v.grid(row=1,column=0) def
here is some code: from Tkinter import * class Main(object): def __init__(self): self.console =
I have the following code: from tkinter import * class MyApplication(Tk): def __init__(self): super().__init__()
I've created this simple GUI: from tkinter import * root = Tk() def grabText(event):
How does adding master = Tk() into the __init__ of a subclass of tkinter.Frame
Here is my code: from tkinter import * from tkinter.ttk import * class App:
from Tkinter import * app = Tk() text_field = Entry(app) text_field.pack() app.mainloop() I want

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.