如果“扫描”被点击,就创建新窗口,叫扫描病毒添加返回键移到右上角:

import tkinter as tk from tkinter import PhotoImage

class IconButton(tk.Button): def init(self, master=None, **kwargs): super().init(master, **kwargs) self.config(text="", compound=tk.LEFT)

def scan(): # 扫描操作的代码 print("正在扫描...") # result = pyclamav.scan_file("file_to_scan.txt") # if result == "OK": # print("扫描完成,未发现病毒") # else: # print("扫描完成,发现病毒") create_new_window()

def create_new_window(): new_window = tk.Toplevel(window) new_window.title("扫描病毒") new_window.geometry("400x300") new_window.protocol("WM_DELETE_WINDOW", on_close)

# 创建返回按钮
return_icon = PhotoImage(file="return_icon.png")
return_button = IconButton(new_window, image=return_icon, command=close_new_window, bg=new_window.cget('bg'), highlightthickness=0, bd=0)
return_button.place(x=370, y=10)

def on_close(): # 处理关闭新窗口的逻辑 print("关闭新窗口")

def close_new_window(): new_window.destroy()

创建主窗口

window = tk.Tk() window.title("杀毒软件") window.geometry("400x300")

创建背景图片

background_image = PhotoImage(file="background.png") background_label = tk.Label(window, image=background_image) background_label.place(x=0, y=0, relwidth=1, relheight=1)

创建图标

scan_icon = PhotoImage(file="scan_icon.png") scan_button = IconButton(window, image=scan_icon, command=scan, bg=window.cget('bg'), highlightthickness=0, bd=0) scan_button.place(x=10, y=240)

运行主循环

window.mainloop(

如果扫描被点击就创建新窗口叫扫描病毒添加返回键移到右上角:import tkinter as tkfrom tkinter import PhotoImageclass IconButtontkButton def __init__self master=None kwargs super__init__master kwargs selfconfigtext=

原文地址: https://www.cveoy.top/t/topic/iruJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录