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