From kivy. Clock import clock.
From kivymd. App import mdapp.
From kivymd. Uix. Boxlayout import mdboxlayout.
From kivymd. Uix. Button import mdraisedbutton.
From kivymd. Uix. Textfield import mdtextfield.
From kivymd. Uix. Label import mdlabel.
From datetime import datetime.
Class countdownapp(mdboxlayout):
Def init(self, **kwargs):
super().init(**kwargs)
Self. Orientation = "vertical"
Self. Padding = 20.
Self. Spacing = 20.
# Başlık.
Self. Add_widget(
Mdlabel(
Text="geri sayım uygulaması",
Halign="Center",
Font_style="h5",
)
)
# Tarih girişi.
Self. Date_input = mdtextfield(
Hint_text="tarih (yyyy-mm-dd)", size_hint=(1, none), height="50DP"
)
Self. Add_widget(self. Date_input)
# Saat girişi.
Self. Time_input = mdtextfield(
Hint_text="saat (hh:MM:SS)", size_hint=(1, none), height="50DP"
)
Self. Add_widget(self. Time_input)
# Geri sayım etiketi.
Self. Countdown_label = mdlabel(
Text="kalan süre burada görünecek",
Halign="Center",
Theme_text_color="primary",
)
Self. Add_widget(self. Countdown_label)
# Başlat butonu.
Self. Start_button = mdraisedbutton(
Text="geri sayımı başlat",
Pos_hint={"center_x": 0.5},
Md_bg_color=(0.1, 0.5, 1, 1),
On_release = self. Start_countdown,
)
Self. Add_widget(self. Start_button)
# Geri sayım için değişkenler.
Self. Remaining_time = none.
Self. Event = none.
Def start_countdown(self, instance):
Try:
# Kullanıcıdan alınan tarih ve saat.
Date_str = self. Date_input. Text.
Time_str = self. Time_input. Text.
Target_time = datetime. Strptime(F"{date_str} {time_str}", "%y-%m-%d %h:%m:%s")
# Şimdiki zaman ile hedef zaman arasındaki fark.
Now = datetime.now()
Self. Remaining_time = (target_time - now).total_seconds()
İf self. Remaining_time > 0:
# Geri sayımı başlat.
İf self. Event:
Clock. Unschedule(self. Event)
Self. Event = clock. Schedule_interval(self. Update_countdown, 1)
Else:
Self. Countdown_label. Text = "geçmiş bir tarih seçemezsiniz!"
Except exception as e:
Self. Countdown_label. Text = "hatalı format! Lutfan doğru giriniz."
Def update_countdown(self, dt):
İf self. Remaining_time > 0:
Self. Remaining_time -= 1
Hours, remainder = divmod(self. Remaining_time, 3600)
Minutes, seconds = divmod(remainder, 60)
Self. Countdown_label. Text = F"kalan süre: {int(hours):02}:{int(minutes):02}:{int(seconds):02}"
Else:
Clock. Unschedule(self. Event)
Self. Countdown_label. Text = "süre bitti!"
Class countdownapplauncher(mdapp):
Def Build(self):
Self. Theme_cls. Primary_palette = "blue" # ana renk.
Self. Theme_cls. Theme_style = "light" # açık tema.
Return CountdownApp()
İf name == "main":
CountdownAppLauncher().run()
Bu kodum biraz basit ama bu kodu APK olarak yapamadım yardım etseniz olur mu?