Dijital saat yapımı tkinter

  • Konuyu başlatan Konuyu başlatan nt
  • Başlama tarihi Başlama tarihi

nt

Emekli
Katılım
21 Nisan 2023
Mesajlar
1,221
Selam!

Sizlere tkinter kütüphanesi kullanılarak bir dijital saat uygulamasını nasıl yapılır onu göstericeğim.
Programı çalıştırdığınızda, şık bir dijital saat arayüzü karşınıza çıkacak.
tkinter kütüphanesi python ile birlikte gelir exra bir yüklemeye ihtiyac duymaz.

öncelikle font'a ihtiyacınız var bunun için dijital font indirip font lara eklemelisiniz
şimdi koda geçelim

Kod:
import tkinter
from tkinter import *
from tkinter.ttk import *
from time import strftime

master=tkinter.Tk()
master.title("Dijital Saat")
label = Label(master,font=("Digital-7",240,''),background = 'Black', foreground='White')

def time():
  string=strftime("%H:%M:%S ")
  label.config(text=string)
  label.after(1000,time)

label.pack(anchor='center')
time()

master.mainloop()

kodda istediğiniz fontu kullanabiliriniz Digital-7 yerine istediğiniz fontu yazınız

Ekran Görüntüsü - 2023-11-28 17-01-42.png
 
Son düzenleme:
:kuskun1: :)

Kod:
import tkinter as tk
import time

root = tk.Tk()
root.title("Saat Uygulaması")

label = tk.Label(root, font=("Courier", 80), bg="white")
label.pack()

def update_time():
    label.config(text=time.strftime("%H:%M:%S"))
    root.after(1000, update_time)

update_time()
root.mainloop()
 
:kuskun1: :)

import tkinter as tk
import time

root = tk.Tk()
root.title("Saat Uygulaması")

label = tk.Label(root, font=("Courier", 80), bg="white")
label.pack()

def update_time():
label.config(text=time.strftime("%H:%M:%S"))
root.after(1000, update_time)

update_time()
root.mainloop()
yüzbinlerce var
ayrıca kodu lütfen kod halinde yazarmısın
:D
 
Aldim code icine. Benim yazdigim 3 satir daha kisa. Daha kisasini yaz da gorelim. :D
bir satır daha kısası
Kod:
import tkinter as tk
import time

root = tk.Tk()

label = tk.Label(root, font=("Courier", 80), bg="white")
label.pack()

def update_time():
    label.config(text=time.strftime("%H:%M:%S"))
    root.after(1000, update_time)

update_time()
root.mainloop()
:katil1:
 
bir satır daha kısası
Kod:
import tkinter as tk
import time

root = tk.Tk()

label = tk.Label(root, font=("Courier", 80), bg="white")
label.pack()

def update_time():
    label.config(text=time.strftime("%H:%M:%S"))
    root.after(1000, update_time)

update_time()
root.mainloop()
:katil1:
Pis. Kurtardin mi diskini?
 
Her şey kod mu? :cool:
Diğerinin kodları daha paylaşmaya hazır değil.
Düzenlenmesi gereken çok yer var.

Kod:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'''
https://www.nvidia.com/en-us/geforce/forums/game-ready-drivers/13/298891/nvidia-smi-get-number-of-fans-2070-has-two/
https://www.microway.com/hpc-tech-tips/nvidia-smi_control-your-gpus/
'''

import PySimpleGUI as sg
import time
import subprocess

mevsim = "kis"
genislik = 160
yukseklik = 100
mandal = 0
cmd11 = 'nvidia-settings -q gpucoretemp -t'
cmd12 = "nvidia-settings -q all| ack -i gpucurrentfanspeedrpm"

#İlk çalıştırmada "mevsim" seçimi
if(mevsim == "yaz"):
    cmd2 = 'nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=50'
    mevsim_str = "yaz"
elif(mevsim == "kis"):
    cmd2 = 'nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=23' #40
    mevsim_str = "kış"
else:
    cmd2 = "Hata"

#-----------------------------
def fan_hiz_ayarla():
    subprocess.check_output(cmd2, shell = True)

#-----------------------------
def fan_devir_oku_gpu():
    res = subprocess.check_output(cmd12, shell = True)
    deger = res.split()[3].decode("utf-8").strip(".")
    return deger

#-----------------------------
def sicaklik_oku_gpu():
    res = subprocess.check_output(cmd11, shell = True)
    deger = res
    return deger

# --------------------------------
sg.theme('LightGrey6')
sg.set_options(element_padding=(0, 0))

layout = [[sg.Text(size=(30, 1), font=('Segment7', 12), justification='center', key='-SICAKLIK-', text_color='red', background_color='darkred')],
          [sg.Text(size=(30, 1), font=('Segment7', 10), justification='center', key='-FANDEVIR-', text_color='red', background_color='darkred')],
          [sg.Checkbox(text="", key='-CHECK-', text_color="gray", background_color="green", enable_events=True), sg.Text(size=(30, 1), font=("Helvetica bold", 10), justification='center', key='-MEVSIM-', text_color='black', background_color='gray')],
          [sg.Exit("Çıkış", size=(30,1), font=("Helvetica", 8))]
          ]

window = sg.Window('GPU Sıcaklığı', layout, no_titlebar=True, auto_size_buttons=True, keep_on_top=True, grab_anywhere=True, size=(genislik, yukseklik), location=(1200 - (75 + genislik), 0))
fan_hiz_ayarla()

# --------------------------------
while (True):
    event, values = window.read(timeout=1000)
    
    sicaklik = int(sicaklik_oku_gpu())
    fandevir = int(fan_devir_oku_gpu())

    if event is None or event == 'Çıkış' or event == sg.WINDOW_CLOSED:
        break
    
    window['-SICAKLIK-'].update('{:3d}°C'.format(sicaklik))
    window['-FANDEVIR-'].update('{:4d} dd'.format(fandevir))
    window['-MEVSIM-'].update(' Fan {:s} ayarında.'.format(mevsim_str))

    if values["-CHECK-"] and mandal==0:
        cmd2 = 'nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=50'
        mevsim_str = "yaz"
        fan_hiz_ayarla()
        mandal=1
    elif not(values["-CHECK-"]) and mandal==1:
        cmd2 = 'nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=23' #40
        mevsim_str = "kış"
        fan_hiz_ayarla()
        mandal = 0
    
#-----------------------------
try:
    window.Close()
except:
    window.Close()
 
Her şey kod mu? :cool:
Diğerinin kodları daha paylaşmaya hazır değil.
Düzenlenmesi gereken çok yer var.

Kod:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'''
https://www.nvidia.com/en-us/geforce/forums/game-ready-drivers/13/298891/nvidia-smi-get-number-of-fans-2070-has-two/
https://www.microway.com/hpc-tech-tips/nvidia-smi_control-your-gpus/
'''

import PySimpleGUI as sg
import time
import subprocess

mevsim = "kis"
genislik = 160
yukseklik = 100
mandal = 0
cmd11 = 'nvidia-settings -q gpucoretemp -t'
cmd12 = "nvidia-settings -q all| ack -i gpucurrentfanspeedrpm"

#İlk çalıştırmada "mevsim" seçimi
if(mevsim == "yaz"):
    cmd2 = 'nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=50'
    mevsim_str = "yaz"
elif(mevsim == "kis"):
    cmd2 = 'nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=23' #40
    mevsim_str = "kış"
else:
    cmd2 = "Hata"

#-----------------------------
def fan_hiz_ayarla():
    subprocess.check_output(cmd2, shell = True)

#-----------------------------
def fan_devir_oku_gpu():
    res = subprocess.check_output(cmd12, shell = True)
    deger = res.split()[3].decode("utf-8").strip(".")
    return deger

#-----------------------------
def sicaklik_oku_gpu():
    res = subprocess.check_output(cmd11, shell = True)
    deger = res
    return deger

# --------------------------------
sg.theme('LightGrey6')
sg.set_options(element_padding=(0, 0))

layout = [[sg.Text(size=(30, 1), font=('Segment7', 12), justification='center', key='-SICAKLIK-', text_color='red', background_color='darkred')],
          [sg.Text(size=(30, 1), font=('Segment7', 10), justification='center', key='-FANDEVIR-', text_color='red', background_color='darkred')],
          [sg.Checkbox(text="", key='-CHECK-', text_color="gray", background_color="green", enable_events=True), sg.Text(size=(30, 1), font=("Helvetica bold", 10), justification='center', key='-MEVSIM-', text_color='black', background_color='gray')],
          [sg.Exit("Çıkış", size=(30,1), font=("Helvetica", 8))]
          ]

window = sg.Window('GPU Sıcaklığı', layout, no_titlebar=True, auto_size_buttons=True, keep_on_top=True, grab_anywhere=True, size=(genislik, yukseklik), location=(1200 - (75 + genislik), 0))
fan_hiz_ayarla()

# --------------------------------
while (True):
    event, values = window.read(timeout=1000)
  
    sicaklik = int(sicaklik_oku_gpu())
    fandevir = int(fan_devir_oku_gpu())

    if event is None or event == 'Çıkış' or event == sg.WINDOW_CLOSED:
        break
  
    window['-SICAKLIK-'].update('{:3d}°C'.format(sicaklik))
    window['-FANDEVIR-'].update('{:4d} dd'.format(fandevir))
    window['-MEVSIM-'].update(' Fan {:s} ayarında.'.format(mevsim_str))

    if values["-CHECK-"] and mandal==0:
        cmd2 = 'nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=50'
        mevsim_str = "yaz"
        fan_hiz_ayarla()
        mandal=1
    elif not(values["-CHECK-"]) and mandal==1:
        cmd2 = 'nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=23' #40
        mevsim_str = "kış"
        fan_hiz_ayarla()
        mandal = 0
  
#-----------------------------
try:
    window.Close()
except:
    window.Close()
Tabii, kod yaristiriyoruz burada. :D

Edit : Ben de niye calismiyor diyorum. Basta path varmis, hem zaten benim NVidia ekran kartim da yok ki. :bilmem1: :cheeky5:
 
Benim kodlar yarışmaz, her zaman optimize değildir.
 
Bu kodları nasıl çalıştırıyorsunuz?
Hangi programın yüklü olması gerekiyor?
İşletim sistemim Windows 7 32 bit var
 

Çevrimiçi personel

Forum istatistikleri

Konular
7,723
Mesajlar
128,553
Üyeler
3,118
Son üye
konce

Son kaynaklar

Son profil mesajları

Python Geliştirmeye eklediğim yapay zeka sunucusu, yeni başlayanlar için roket etkisi
Bir insanın zeka seviyesinin en kolay tesbiti, sorduğu sorulardır.
yapay zeka interneti yedi bitirdi, arama motoru kullanan, forumlara yazan kaldı mı ?
Freemont2.0 herbokolog Freemont2.0 wrote on herbokolog's profile.
nick iniz yakıyor
:D
az bilgili çok meraklı
Back
Top