# https://paste.ofcode.org/J3zqY9SPYhHYMBSa5WgRbc
import tkinter as tk
from tkinter import messagebox, font
import os
def save_info():
try:
with open("info.txt", "w") as f:
f.write(f"{rstp_link_var.get()}\n")
f.write(f"{video_link_var.get()}\n")
f.write(f"{sender_email_var.get()}\n")
f.write(f"{receiver_email_var.get()}\n")
f.write(f"{password_var.get()}\n")
messagebox.showinfo("Thông báo", "Lưu thông tin thành công!")
except Exception as e:
messagebox.showerror("Lỗi", f"Không thể lưu thông tin: {e}")
def load_info():
try:
if os.path.exists("info.txt"):
with open("info.txt", "r") as f:
lines = f.readlines()
rstp_link_var.set(lines[0].strip())
video_link_var.set(lines[1].strip())
sender_email_var.set(lines[2].strip())
receiver_email_var.set(lines[3].strip())
password_var.set(lines[4].strip())
time_var.set(lines[5].strip())
messagebox.showinfo("Thông báo", "Load thông tin thành công!")
else:
messagebox.showerror("Lỗi", "Không tìm thấy file thông tin!")
except Exception as e:
messagebox.showerror("Lỗi", f"Không thể load thông tin: {e}")
# Tạo window
root = tk.Tk()
icon = tk.PhotoImage(file='jp.png') # Assuming you have converted cam.ico to cam.png
root.iconphoto(False, icon)
root.title("Input Information")
# Đặt màu nền và font chung
root.configure(bg='#F5F5F5')
app_font = font.Font(family='Yu Gothic UI', size=10)
# Tạo và khởi tạo các biến
rstp_link_var = tk.StringVar()
video_link_var = tk.StringVar()
sender_email_var = tk.StringVar()
receiver_email_var = tk.StringVar()
password_var = tk.StringVar()
time_var = tk.StringVar()
# Set thời gian mặc định là "5:30"
time_var = tk.StringVar(value="5:30")
# Tạo và sắp xếp các widget
tk.Label(root, text="Camera Link", bg='#F5F5F5', font=app_font).grid(row=0, column=0, pady=5, padx=5, sticky='e')
tk.Entry(root, textvariable=rstp_link_var, width=40, font=app_font).grid(row=0, column=1, columnspan=2, pady=5, padx=10)
tk.Label(root, text="Video Link", bg='#F5F5F5', font=app_font).grid(row=1, column=0, pady=5, padx=5, sticky='e')
tk.Entry(root, textvariable=video_link_var, width=40, font=app_font).grid(row=1, column=1, columnspan=2, pady=5, padx=5)
tk.Label(root, text="Sender Email", bg='#F5F5F5', font=app_font).grid(row=2, column=0, pady=5, padx=5, sticky='e')
tk.Entry(root, textvariable=sender_email_var, width=40, font=app_font).grid(row=2, column=1, columnspan=2, pady=5, padx=5)
tk.Label(root, text="Receiver Email", bg='#F5F5F5', font=app_font).grid(row=3, column=0, pady=5, padx=5, sticky='e')
tk.Entry(root, textvariable=receiver_email_var, width=40, font=app_font).grid(row=3, column=1, columnspan=2, pady=5, padx=5)
tk.Label(root, text="Sender Password", bg='#F5F5F5', font=app_font).grid(row=4, column=0, pady=5, padx=5, sticky='e')
tk.Entry(root, textvariable=password_var, show='*', width=40, font=app_font).grid(row=4, column=1, columnspan=2, pady=5, padx=5)
tk.Label(root, text="Report Time", bg='#F5F5F5', font=app_font).grid(row=5, column=0, pady=5, padx=5, sticky='e')
tk.Entry(root, textvariable=time_var, width=40, font=app_font).grid(row=5, column=1, columnspan=2, pady=5, padx=5)
tk.Button(root, text="Save", command=save_info, font=app_font).grid(row=6, column=0, pady=5, padx=5)
tk.Button(root, text="Load", command=load_info, font=app_font).grid(row=6, column=1, pady=5, padx=5)
tk.Button(root, text="Run", command=load_info, font=app_font).grid(row=6, column=2, pady=5, padx=5)
# Bắt đầu loop chính của Tkinter
root.mainloop()