mirror of
https://github.com/Xevion/tkinter-mini-projects.git
synced 2025-12-05 23:16:36 -06:00
28 lines
978 B
Python
28 lines
978 B
Python
from tkinter import *
|
|
from functools import partial
|
|
|
|
def add_buttons():
|
|
# Add buttons
|
|
for i in range(10):
|
|
Button(main, text=str(i), command=partial(print, i)).pack()
|
|
|
|
# search for "Add Buttons" Button object and change text and function
|
|
for child in main.winfo_children():
|
|
if child.cget('text') == 'Add Buttons':
|
|
child.config(text='Delete all buttons')
|
|
child.config(command=delete_buttons)
|
|
|
|
def delete_buttons():
|
|
# search for buttons and delete all except the 'Delete' Button
|
|
for child in main.winfo_children():
|
|
if child.winfo_class() == 'Button':
|
|
if child.cget('text') == 'Delete all buttons':
|
|
# change "Delete" button text and function
|
|
child.config(text='Add Buttons')
|
|
child.config(command=add_buttons)
|
|
else:
|
|
child.destroy()
|
|
|
|
main = Tk()
|
|
Button(main,text='Add Buttons', command=add_buttons).pack()
|
|
main.mainloop() |