Jul-20-2018, 08:34 AM
Hello all,
I have got this code which should open a GUI with two buttons, one saying Hello, the other one QUIT which it does. When QUIT button is pressed the application should close which it does, and when Hello button is pressed new button should be gridded onto the application in a row number 1 and also disable a Hello button. And when newly gridded button is pressed it should delete itself of the grid and reactivate Hello button, but for some reason, it does not do that. Any ideas why?
I have got this code which should open a GUI with two buttons, one saying Hello, the other one QUIT which it does. When QUIT button is pressed the application should close which it does, and when Hello button is pressed new button should be gridded onto the application in a row number 1 and also disable a Hello button. And when newly gridded button is pressed it should delete itself of the grid and reactivate Hello button, but for some reason, it does not do that. Any ideas why?
from tkinter import * class Application(Frame): def new_button(self): print("enable_b") self.hi_there.config(state=ACTIVE) self.new_button.grid_remove() def say_hi(self): print("hi there, everyone!") self.new_button = Button(self) self.new_button["text"] = "New BTN" self.new_button.grid(row=1,column=0) self.hi_there.config(state=DISABLED, command=self.new_button) def createWidgets(self): self.QUIT = Button(self) self.QUIT.config(text="QUIT",fg="red",command=self.quit) self.QUIT.grid(row=0,column=1) self.hi_there = Button(self) self.hi_there["text"] = "Hello", self.hi_there["command"] = self.say_hi self.hi_there.grid(row=0,column=0) def __init__(self, master=None): Frame.__init__(self, master) self.pack() self.createWidgets() root = Tk() app = Application(master=root) app.mainloop() root.destroy()