You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import tkinter as tk
from tkinter import *
from data import CPU
import time
cpu = CPU()
WORD = '#00f5ff'
color1 = '#ee28a3'
color2 = '#668B8B'
NOMARK = '#c5c9c5'
NOMARK1 = NOMARK
BLUE = "#0080FF"
BLACK = "#000000"
WHITE = "#FFFFFF"
RED = "#FFAAAA"
NORED = NOMARK1 # '#ffdddd'
YELLOW = "#FFFACD"
GREY = '#808080'
GOLD = '#FFD700'
GREEN = '#00FA9A'
NOGREEN = NOMARK1 # '#00321f'
BACK = '#0153d2'
ORANGE = '#d3b719'
NOORANGE = NOMARK1 # '#ede2a3'
MEMBACK = '#fba651'
MEMMARK = '#fd280f'
MEMWORD = '#000000'
width = 1000 #设置窗口宽度
height = 700 #设置窗口高度
root = tk.Tk() #设置主框架
root.title("CPU可视化") #设置标题
root.config(bg=BLACK) #设置背景颜色
root.geometry(f'{width + 300}x{height}') #设置大小
cv = tk.Canvas(root, bg='white', bd=2, relief="sunken", width=width + 300, height=height, background=BLACK,
borderwidth=0, highlightthickness=0) #设置画布
cv.place(x=0, y=0, anchor=NW) #放置画布
def round_rectangle(x1, y1, x2, y2, r=25, **kwargs):
points = (
x1 + r, y1, x1 + r, y1, x2 - r, y1, x2 - r, y1, x2, y1, x2, y1 + r, x2, y1 + r, x2, y2 - r, x2, y2 - r, x2, y2,
x2 - r, y2, x2 - r, y2, x1 + r, y2, x1 + r, y2, x1, y2, x1, y2 - r, x1, y2 - r, x1, y1 + r, x1, y1 + r, x1, y1)
return cv.create_polygon(points, **kwargs, smooth=True)
# cv.grid(row=1,column=0)
# cv.create_oval(20,20,40, 40, fill='red',width=0)
# image = Image.open('image/CPU2.png')
# im = ImageTk.PhotoImage(image)
root_right = tk.Frame(root, bg=WHITE, relief="groove", width=250, height=height - 80)
root_right.place(x=width + 20, y=40, anchor=NW) # 右边栏
round_rectangle(width + 20, 15, width + 270, height - 25, r=25, fill=WHITE, width=0)
round_rectangle(20, 15, 970, height - 25, r=25, fill=WHITE, width=0)
# cv.create_image(0, 0, anchor=NW, image=im)
# cv.create_rectangle(0, 0, width, 10, fill=WHITE, width=0)
# cv.create_rectangle(20, 14, 30, 674, fill=WHITE, width=0)
#
# cv.create_rectangle(710, 24, 925, 140, fill=WHITE, width=0)
# cv.create_rectangle(77, 434, 533, 642, fill=color1, width=0)
def use_rgb(rgb):
"""
将rgb转十六进制
Args:
rgb: rgb颜色
Returns: 十六进制
"""
rgb = str(rgb)
RGB = rgb.replace('(', '').replace(")", '').split(',') # 将RGB格式划分开来
color = "#"
for i in RGB:
num = int(i)
# 将R、G、B分别转化为16进制拼接转换并大写 hex() 函数用于将10进制整数转换成16进制以字符串形式表示
color += str(hex(num))[-2:].replace('x', '0')
# for i in range(len(color)):
# if color[i] >= 'a' and color[i] <= 'z':
# c = int(color[i]) + int('A') - int('a')
# color[i] = str[c]
return color.upper()
if __name__ == "__main__":
# print(use_rgb((225, 225, 225)))
def left1(event):
print(event.x, event.y)
cv.bind('<Button-1>', left1)
mainloop()#执行GUI界面