# 根号七的工具箱
import tkinter as tk
from PIL import Image, ImageTk
import webbrowser
from tkinter import messagebox

# 初始化
root = tk.Tk()
root.title("根号七的工具箱")
root.geometry("1080x720")
root.state("zoomed")

try:
    root.iconbitmap("根号七的工具箱图标.ico")
except:
    pass

#渐变背景
def create_gradient(canvas, width, height, color1, color2):
    r1, g1, b1 = canvas.winfo_rgb(color1)
    r2, g2, b2 = canvas.winfo_rgb(color2)
    r_ratio = (r2 - r1) / height
    g_ratio = (g2 - g1) / height
    b_ratio = (b2 - b1) / height

    for i in range(height):
        nr = int(r1 + (r_ratio * i))
        ng = int(g1 + (g_ratio * i))
        nb = int(b1 + (b_ratio * i))
        color = f"#{nr:04x}{ng:04x}{nb:04x}"
        canvas.create_line(0, i, width, i, fill=color)

# 创建画布
c = tk.Canvas(root, highlightthickness=0)
c.pack(fill=tk.BOTH, expand=True)

# 窗口刷新后获取真实宽高，绘制渐变
root.update()
w = root.winfo_width()
h = root.winfo_height()
create_gradient(c, w, h, "#99FFCC", "#66CCFF")

# 设置标题
x, y = 10, 10
text = "根号七的工具箱"
font = ("微软雅黑", 50)

# 绘制描边
for dx, dy in [(-1,0),(1,0),(0,-1),(0,1)]:
    c.create_text(x+dx, y+dy, text=text, font=font, fill="black", anchor="nw")

# 绘制主文字
c.create_text(x, y, text=text, font=font, fill="#00FF00", anchor="nw")

# 导入标题图片
try:
    img = Image.open("根号七的工具箱标题图标.png")
    img = img.resize((100, 100))
    photo_title = ImageTk.PhotoImage(img)
    c.create_image(500, 10, image=photo_title, anchor="nw")
    c.image_title = photo_title  # 单独保存
except:
    print("标题图标未找到")

# 设置首分割线
x, y = 2.5, 60
text = "------------------------------------------------------------------"
font = ("微软雅黑", 60)

for dx, dy in [(-1,0),(1,0),(1,0),(0,-1),(0,1)]:
    c.create_text(x+dx, y+dy, text=text, font=font, fill="black", anchor="nw")

c.create_text(x, y, text=text, font=font, fill="#00FF00", anchor="nw")

# 按钮操作 - B站
def open_bilibili():
    print('按钮1弹窗')
    result = messagebox.askyesno("工具箱：提示", "是否打开Bilibili网站？")
    if result:
        print('按钮1执行')
        webbrowser.open("https://www.bilibili.com")

# 按钮1图形
btn = tk.Button(
    root,
    text="打开网页版\nBilibili",
    font=("微软雅黑", 16),
    bg="#99FFFF",
    fg="#000",
    activebackground="#00CCCC",
    activeforeground="#000",
    width=12,
    height=5,
    command=open_bilibili
)
btn.place(x=25, y=145)

# 按钮1正方形边框
c.create_rectangle(
    20, 140,
    195, 310,
    outline="#00FF00",
    width=10,
    fill=""
)

# 按钮2图形
btn = tk.Button(
    root,
    text="暂无功能\n求投稿！！！",
    font=("微软雅黑", 16),
    bg="#99FFFF",
    fg="#000",
    activebackground="#00CCCC",
    activeforeground="#000",
    width=12,
    height=5,
)
btn.place(x=225, y=145)

# 按钮2正方形边框
c.create_rectangle(
    220, 140,
    395, 310,
    outline="#00FF00",
    width=10,
    fill=""
)

# 尾分割线
x, y = 2.5, 850
text = "------------------------------------------------------------------"
font = ("微软雅黑", 50)

for dx, dy in [(-1,0),(1,0),(1,0),(0,-1),(0,1)]:
    c.create_text(x+dx, y+dy, text=text, font=font, fill="black", anchor="nw")

c.create_text(x, y, text=text, font=font, fill="#00FF00", anchor="nw")

# 赞助文字
x, y = 10, 920
text = "赞助根号七！"
font = ("微软雅黑", 50)

for dx, dy in [(-1,0),(1,0),(0,-1),(0,1)]:
    c.create_text(x+dx, y+dy, text=text, font=font, fill="black", anchor="nw")

c.create_text(x, y, text=text, font=font, fill="#00FF00", anchor="nw")

# 赞赏码
try:
    img = Image.open("根号七的赞赏码.png")
    img = img.resize((100, 100))
    photo_zanshang = ImageTk.PhotoImage(img)
    c.create_image(390, 910, image=photo_zanshang, anchor="nw")
    c.image_zanshang = photo_zanshang
except:
    print("赞赏码图片未找到")

# 交流群文字
x, y = 500, 920
text = "| 加入交流群！"
font = ("微软雅黑", 50)

for dx, dy in [(-1,0),(1,0),(0,-1),(0,1)]:
    c.create_text(x+dx, y+dy, text=text, font=font, fill="black", anchor="nw")

c.create_text(x, y, text=text, font=font, fill="#00FF00", anchor="nw")

# 交流群图
try:
    img_q = Image.open("交流群.png")
    img_q = img_q.resize((100, 100))
    photo_jiaoliuqun = ImageTk.PhotoImage(img_q)
    c.create_image(920, 910, image=photo_jiaoliuqun, anchor="nw")
    c.image_jiaoliuqun = photo_jiaoliuqun
except:
    print("交流群图片未找到")

# 交流群号码
x, y = 800, 910
text = "群号1083170749"
font = ("微软雅黑", 10)

for dx, dy in [(-1,0),(1,0),(0,-1),(0,1)]:
    c.create_text(x+dx, y+dy, text=text, font=font, fill="black", anchor="nw")

c.create_text(x, y, text=text, font=font, fill="#00FF00", anchor="nw")

# B站关注文字1
x, y = 1030, 920
text = "| B站关注                   ！"
font = ("微软雅黑", 50)

for dx, dy in [(-1,0),(1,0),(0,-1),(0,1)]:
    c.create_text(x+dx, y+dy, text=text, font=font, fill="black", anchor="nw")

c.create_text(x, y, text=text, font=font, fill="#00FF00", anchor="nw")

# B站关注文字2
x, y = 1320, 915
text = "根号七大玉"
font = ("微软雅黑", 55)

for dx, dy in [(-1,0),(1,0),(0,-1),(0,1)]:
    c.create_text(x+dx, y+dy, text=text, font=font, fill="black", anchor="nw")

c.create_text(x, y, text=text, font=font, fill="#FF8000", anchor="nw")

# 按钮操作 - B站 - 根号七大玉
def open_space_bilibili():
    print('关注按钮弹窗')
    result = messagebox.askyesno("工具箱：提示", "是否打开Bilibili网站, 根号七大玉 主页？")
    if result:
        print('关注按钮执行')
        webbrowser.open("https://space.bilibili.com/3493288684292639")

# 关注按钮图形
btn = tk.Button(
    root,
    text="立即关注",
    font=("微软雅黑", 16),
    bg="#99FFFF",
    fg="#000",
    activebackground="#00CCCC",
    activeforeground="#000",
    width=12,
    height=3,
    command=open_space_bilibili
)
btn.place(x=1730, y=910)

print('初始化完成！')
root.mainloop()
#由三分之根号七制作
#交流群1083170749
#B站 根号七大玉 -> https://space.bilibili.com/3493288684292639