mirror of
https://github.com/Xevion/tkinter-mini-projects.git
synced 2025-12-06 01:16:37 -06:00
init
This commit is contained in:
28
buttons.py
Normal file
28
buttons.py
Normal file
@@ -0,0 +1,28 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user