from tkinter import * def button_clicked(): bg = '#%0x%0x%0x' % (int(random()*16), int(random()*16), int(random()*16)) button['bg'] = bg button['activebackground'] = bg root=Tk() button = Button(root, command=button_clicked) button.pack() root.mainloop() destroy usuli - destroy usuli Vidjet va uning nusxalarini vayron qilish (yo`qotish). Shuni aytib o'tish joizki, faqat bir muddat vidjetni yashirish kerak bo`lsa, grid packer va grid_remove usulidan foydalanish yaxshiroq:
Misol - from tkinter import *
- def hide_show():
- if label.winfo_viewable():
- label.grid_remove()
- else:
- label.grid()
- root=Tk()
- label = Label(text=“Bizning ish!')
- label.grid()
- button = Button(command=hide_show, text=“yashrish/ko`rsatish")
- button.grid()
- root.mainloop()
Do'stlaringiz bilan baham: |