Tkinter da asosiy vidjetlar, ularni oynada joylastirish usullari


from tkinter import * from random import random


Download 0.62 Mb.
bet4/14
Sana05.01.2022
Hajmi0.62 Mb.
#202501
1   2   3   4   5   6   7   8   9   ...   14
Bog'liq
tkinter da asosiy vidjetlar, ularni oynada joylastirish

from tkinter import *

from random import random

def button_clicked():

button['text'] = button['bg'] # tugmaning oldingi rangi

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()

Download 0.62 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   14




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling