Я не понимаю, как передать ему команду, если функция определена вне класса.
Код: Выделить всё
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
И мне нужно сделать это через класс/объект, так как я пытаюсь узнать об этом.
Я новичок в материале объекта класса Python и был бы признателен за помощь, чтобы продолжить это.
Спасибо.
Я попробовал использовать «command = self.changeButtonText»:
Код: Выделить всё
input_bt = Button(self.master, text='Yes',width=8,command=self.changeButtonText) # how to add command 'changeButtonText' here?
AttributeError: объект 'GUI' не имеет атрибута 'changeButtonText'
Подробнее здесь: https://stackoverflow.com/questions/785 ... -defined-i