I have defined Class GUI which creates a button with a YES text on it.
I do not understand how I should pass the command to it when the function is defined outside of the Class.
import tkinter as tk
from tkinter import ttk
import pdb
from tkinter import *
def changeButtonText():
input_bt['text'] = 'No'
input_bt['relief'] = 'sunken'
class GUI:
def __init__(self, master) -> None:
root.title('Learning TKinter')
root.resizable(False, False)
color = '#aeb3b0'
root.geometry("100x100")
root.configure(bg=color)
# Instantiating master i.e toplevel Widget
self.master = master
# Creating Button
input_bt = Button(self.master, text='Yes',width=8,command="") # how to add command 'changeButtonText' here?
input_bt.place(relx=0.1, rely=0.2)
input_bt['relief'] = 'raised'
root = tk.Tk()
gui = GUI(root)
root.mainloop() # original working place for root
Basically I want to press the Button so that it goes from Yes to No; and relief raised to sunken.
And i need to do this via Class/Object since I am trying to learn about these.
I am new to Python Class Object material and would appreciate help to get me going on this.
Thank you
I tried using ‘command = self.changeButtonText’:
input_bt = Button(self.master, text='Yes',width=8,command=self.changeButtonText) # how to add command 'changeButtonText' here?
But it is giving me this error:
AttributeError: ‘GUI’ object has no attribute ‘changeButtonText’
ranjit more is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.