Last active
March 25, 2024 16:47
-
-
Save storlak/bad9839e5a8772bf1948cd82ff5c3ffb to your computer and use it in GitHub Desktop.
URL Kısaltıcı. Tinyurl Kullanarak python ile yazılmış tkinter ile basit arayüze sahip URL kısaltıcı.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter | |
from tkinter import ttk | |
import pyshorteners | |
import tkinter.messagebox | |
# URL kısaltmak için fonksiyon | |
def shorten(): | |
url = longurl_entry.get().strip() # URL satırını kontrol et. Boş olmamalı! | |
if not url: | |
tkinter.messagebox.showerror("Hata", "Lütfen bir URL girin.") | |
return | |
try: | |
shortener = pyshorteners.Shortener() | |
short_url = shortener.tinyurl.short(url) | |
shorturl_entry.delete(0, tkinter.END) # Panodan önceki içeriği sil. | |
shorturl_entry.insert(0, short_url) | |
except pyshorteners.exceptions.ShorteningErrorException: | |
tkinter.messagebox.showerror( | |
"Hata", "URL kısaltılırken bir hata oluştu. Lütfen geçerli bir URL girin." | |
) | |
except pyshorteners.exceptions.ServiceException: | |
tkinter.messagebox.showerror( | |
"Hata", | |
"URL kısaltma servisi şu anda kullanılamıyor. Lütfen daha sonra tekrar deneyin.", | |
) | |
except Exception as e: | |
tkinter.messagebox.showerror("Hata", f"Bir hata oluştu: {str(e)}") | |
# Kısaıltmış URL'yi panoya kopyala. | |
def copyurl(): | |
shortened_url = shorturl_entry.get() | |
if shortened_url: | |
root.clipboard_clear() | |
root.clipboard_append(shortened_url) | |
root.update() | |
tkinter.messagebox.showinfo("Başarılı", "Kısaltılmış URL panoya kopyalandı.") | |
else: | |
tkinter.messagebox.showwarning("Uyarı", "Kısaltılmış URL bulunamadı.") | |
# Her iki girişteki datayı temizleme. | |
def clear_entries(): | |
longurl_entry.delete(0, tkinter.END) | |
shorturl_entry.delete(0, tkinter.END) | |
root = tkinter.Tk() | |
root.title("URL Kısaltıcı") | |
root.geometry("300x275") | |
root.configure(bg="gray16") | |
# Labels, entries, widgets | |
longurl_label = tkinter.Label( | |
root, text="Kısaltmak için URL Gir", fg="#FFFFFF", bg="gray16" | |
) | |
longurl_entry = tkinter.Entry(root, width=35) | |
shorten_button = tkinter.Button( | |
root, text="URL'yi kısalt", fg="black", bg="Turquoise", command=shorten | |
) | |
separator = ttk.Separator(root, orient="horizontal") | |
shorturl_label = tkinter.Label(root, text="Kısaltılmış URL", fg="#FFFFFF", bg="gray16") | |
shorturl_entry = tkinter.Entry(root, width=35) | |
copyurl_button = tkinter.Button( | |
root, text="Kopyala", fg="black", bg="Turquoise", command=copyurl | |
) | |
bot_label = tkinter.Label( | |
root, text="Versiyon: 2.0 - Kazure", fg="black", bg="Turquoise" | |
) | |
# Placing widgets, labels, entries | |
longurl_label.pack(pady=5) | |
longurl_entry.pack() | |
shorten_button.pack(pady=5) | |
separator.pack(fill="x", padx=5, pady=5) | |
shorturl_label.pack(pady=5) | |
shorturl_entry.pack() | |
copyurl_button.pack(pady=5) | |
bot_label.pack(side="bottom", fill="x") | |
# Temizle tuşu | |
clear_button = tkinter.Button( | |
root, text="Panoyu Temizle", fg="black", bg="Turquoise", command=clear_entries | |
) | |
clear_button.pack(pady=5) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment