An warware: qtimer

Duniya na fashion yana da sauri-paced kamar yadda yake da bambanci, tare da salo daban-daban, kamannuna, da abubuwan da ke fitowa koyaushe daga catwalks da salon gabaษ—aya. Don ci gaba da kasancewa tare da sabbin kayan zamani, yana da mahimmanci a sami kayan aiki wanda zai iya kiyaye lokaci, tabbatar da cewa al'amura da lokuta suna tafiya cikin sauฦ™i. Wannan shine inda qtimer ya zo da hannu. Qtimer aji ne na QTimer a cikin PyQt, ษ—akin karatu na Python da ake amfani dashi don ฦ™irฦ™irar mu'amalar mai amfani da hoto (GUI). Wannan aji yana ba da masu maimaitawa da masu ฦ™ididdigewa lokaci-lokaci waษ—anda za a iya amfani da su don dalilai daban-daban, kamar ฦ™ara ษ—aukakawa ko rayarwa a cikin aikace-aikacenku. A cikin wannan labarin, za mu bincika yadda ake ฦ™irฦ™ira qtimer, yin zurfafa cikin amfani da aiwatarwa ta hanyar cikakkun bayanai, mataki-mataki bayanin lambar.

Gabatarwa zuwa QTimer da PyQt

PyQt saitin Python ne don tsarin aikace-aikacen Qt, wanda ake amfani dashi don ฦ™irฦ™irar tebur, wayar hannu, da aikace-aikacen da aka haษ—a. Daga cikin azuzuwan da yawa da PyQt ke bayarwa, QTimer yana da amfani musamman don aiwatar da ayyuka a takamaiman tazara ko bayan wani ษ—an lokaci.

QTimer yana ba ku damar ฦ™irฦ™ira duka biyu-harbi da mai maimaita lokaci. Mai ฦ™idayar lokaci-harbi ษ—aya zai aiwatar da ฦ™ayyadaddun aiki sau ษ—aya bayan ฦ™ayyadaddun tazarar lokaci, yayin da mai maimaita ฦ™idayar zai kunna aikin akai-akai a ฦ™ayyadaddun tazara.

Domin fara aiki tare da QTimer, yana da mahimmanci a fahimci yadda PyQt ke aiki. Don yin haka, da farko, shigar da ษ—akin karatu da ake buฦ™ata:

pip install PyQt5

ฦ˜irฦ™irar QTimer

ฦ˜irฦ™irar qtimer ya ฦ™unshi ฦดan matakai masu mahimmanci, waษ—anda za mu bincika dalla-dalla a cikin sakin layi na gaba. Ga ainihin tsarin da za mu bi:

  • Shigo da dakunan karatu da kayan aiki masu mahimmanci
  • ฦ˜irฦ™iri abin QTimer
  • Haษ—a QTimer zuwa aikin al'ada
  • Saita tazarar lokaci kuma fara QTimer

Da farko, muna buฦ™atar shigo da ษ—akunan karatu da kayayyaki da ake buฦ™ata:

from PyQt5.QtCore import QTimer, QCoreApplication
from PyQt5.QtGui import QApplication

Muna shigo da kaya QTimer da kuma QCoreApplication daga PyQt5.QtCore, waษ—anda ake buฦ™ata don ฦ™irฦ™ira da sarrafa masu ฦ™idayar lokaci.

Na gaba, ฦ™irฦ™iri wani abu QTimer tare da tazarar lokaci da aka bayar. Wannan tazara zai ฦ™ayyade yadda akai-akai mai ฦ™idayar lokaci zai fara haifar da takamaiman aiki:

timer = QTimer()
timer.setInterval(1000)  # Sets the timer interval to 1000ms (1 second)

Yanzu, muna buฦ™atar haษ—a wannan mai ฦ™idayar lokaci zuwa aikin da za a aiwatar lokacin da mai ฦ™idayar ta kunna wuta. Ana yin wannan ta amfani da timeout sigina:

def custom_function():
    # Your function code here
    print("Timer triggered!")

timer.timeout.connect(custom_function)

A ฦ™arshe, don fara mai ฦ™idayar lokaci, kira fara() hanya:

timer.start()

Tare da wannan, qtimer ษ—in mu yana aiki cikakke kuma zai aiwatar da custom_function() kowane daฦ™iฦ™a.

Kammalawa da Amfani da Abubuwan

A ฦ™arshe, qtimers kayan aiki ne masu kima a fagen ci gaban PyQt da GUI, suna ba da damar daidaitaccen lokaci da aiwatar da ayyuka. Ta hanyar amfani da ajin QTimer, masu shirye-shirye na iya ฦ™irฦ™irar abubuwan da suka faru, rayarwa, da sabuntawa a cikin aikace-aikacen su.

Wasu lokuta amfani ga qtimers sun haษ—a da:

  • Abubuwan da ke wartsakewa na GUI a tazara na yau da kullun don nuna sabbin bayanai
  • ฦ˜irฦ™irar raye-raye na al'ada da canji don ฦ™arin ฦ™warewar mai amfani mai ban sha'awa
  • Aiwatar da ฦ™ayyadaddun fasali a cikin aikace-aikacen, kamar agogon ฦ™irgawa ko sanarwar tunatarwa

Ta hanyar haษ—a ฦ™arfin Python tare da ajin QTimer a cikin PyQt, ฦ™irฦ™irar aikace-aikace masu ฦ™arfi da saurin lokaci ya zama iska ga masu farawa da ฦ™wararrun masu shirye-shirye iri ษ—aya.

Shafi posts:

Leave a Comment