An warware: tkinter mayar da hankali kan shigarwa

Gabatarwa

Tkinter ษ—akin karatu ne na buษ—e tushen mai amfani da hoto (GUI) don Python, kuma kayan aiki ne mai mahimmanci don ฦ™irฦ™irar aikace-aikacen tebur. ฦŠaya daga cikin amfanin gama-gari na Tkinter shine ฦ™irฦ™irar nau'ikan da ke buฦ™atar shigarwar mai amfani a cikin widgets ษ—in shigarwa, kamar filayen rubutu. Wani muhimmin al'amari na ฦ™irฦ™ira da aiki tare da waษ—annan widgets ษ—in shigarwa shine kulawa da mayar da hankali: ฦ™ayyadaddun ษ“angaren aikace-aikacen zai karษ“i shigarwar daga mai amfani lokacin abubuwan da suka faru na madannai. Wannan labarin zai ba da zurfin nazari kan sarrafa mayar da hankali a cikin widgets na shigarwa tare da Tkinter kuma zai bayyana sassa daban-daban na lambar daki-daki. Bugu da ฦ™ari kuma, zai tattauna dakunan karatu masu alaฦ™a da ayyuka waษ—anda ke taka muhimmiyar rawa wajen amfani da Tkinter don ci gaban GUI.

Fahimtar Mayar da hankali a cikin Tkinter da Widgets na Shiga

Lokacin haษ“aka aikace-aikace ta amfani da Tkinter, yana da mahimmanci don fahimtar manufar mayar da hankali. Mayar da hankali yana nufin ษ“angaren GUI wanda a halin yanzu ke karษ“ar shigarwar madannai. Widget din daya ne kawai zai iya samun mayar da hankali a lokaci guda. Yawanci, widget din da aka mayar da hankali ana nuna shi da gani, kamar ta hanyar haskaka rubutu ko nuna siginan kyaftawa a filin shigarwar rubutu.

  • Babban aikin mayar da hankali shine tabbatar da cewa mai amfani zai iya yin hulษ—a tare da sassan da suka dace na aikace-aikacen a hankali.
  • Don aikace-aikacen tebur, sarrafa mayar da hankali shine muhimmin al'amari na ฦ™warewar mai amfani. Lokacin da masu amfani ke kewayawa ta hanyar tsari, alal misali, ya kamata su iya motsawa tsakanin filayen shigarwa cikin sauฦ™i ba tare da rudani ba.

Don sarrafa mayar da hankali a cikin widgets na shigarwa, Tkinter yana ba da hanyoyi da yawa kamar su focus_set() da focus_get().

Magani: Sarrafa Mayar da hankali a cikin Widgets Shiga Tkinter

Maganin farko don sarrafa mayar da hankali a cikin widgets ษ—in shigarwa shine yin amfani da ayyukan focus_set() da kuma focus_get() ayyukan da Tkinter ke bayarwa. Ga misalin yadda ake amfani da waษ—annan ayyuka:

import tkinter as tk

def focus_next(event):
    event.widget.tk_focusNext().focus_set()

root = tk.Tk()

e1 = tk.Entry(root)
e1.pack()
e1.bind("<Tab>", focus_next)

e2 = tk.Entry(root)
e2.pack()
e2.bind("<Tab>", focus_next)

root.mainloop()

A cikin lambar da ke sama, mun fara shigo da tkinter module kuma mu ฦ™irฦ™iri aiki mai sauฦ™i, focus_next(). Wannan aikin yana ษ—aukar taron azaman shigarwa kuma yana amfani da hanyoyin "tk_focusNext()" da "focus_set()" don saita mai da hankali kan widget din Shiga na gaba. Sai mu ฦ™irฦ™iri taga Tkinter (tushen) da widgets ษ—in shigarwa guda biyu, e1 da e2. Ga kowane widget din shigarwa, muna ษ—aure da maษ“alli zuwa aikin focus_next(). Lokacin da Ana danna maษ“alli yayin da e1 ko e2 ke da hankali, za a karkata hankalin zuwa widget din shigarwa na gaba.

Shafi posts:

Leave a Comment