Skip to content

Commit d66b8b1

Browse files
committed
增加了像素字体文件并修正了加载方法
1 parent 908798c commit d66b8b1

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

assets/Unifont.otf

4.87 MB
Binary file not shown.

main_gui.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import pyglet
23
import tkinter
34
from widgets import *
45
from tkinter import font
@@ -42,6 +43,8 @@ def config_root_window(self): # 设置窗体
4243
self.style.theme_use("solar")
4344
self.wm_geometry("754x730")
4445
self.place_window_center()
46+
pyglet.options['win32_gdi_font'] = True
47+
pyglet.font.add_file("assets/Unifont.otf")
4548

4649
def pack_widgets(self):
4750
self.title_bar.pack(fill=X, padx=10)

widgets.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from tkinter.font import Font
2+
13
from ttkbootstrap import Style
24
from ttkbootstrap.constants import *
35
from scanner import ServerInfo
@@ -6,7 +8,7 @@
68
from colorlib import Color
79
from tkinter import Misc
810
from typing import Any
9-
from copy import copy
11+
from copy import copy, deepcopy
1012
import tkinter as tk
1113
import vars
1214

@@ -31,7 +33,7 @@ def __load_motd(self):
3133
for extra in self.data.description_json:
3234
try:
3335
tag = hex(randint(0, 114514))
34-
tag_font = ("Unifont", 12)
36+
tag_font = Font(family="Unifont", size=12)
3537
if extra.get("color"):
3638
if "#" not in extra["color"]:
3739
color = vars.color_map_hex[extra["color"]]
@@ -42,14 +44,11 @@ def __load_motd(self):
4244
if extra.get("underline") or extra.get("underlined"):
4345
self.tag_configure(tag, underline=True)
4446
if extra.get("bold"):
45-
tag_font += ("bold",)
46-
tag_font = list(tag_font)
47-
tag_font[0] = "宋体"
48-
tag_font = tuple(tag_font)
47+
tag_font.config(family="宋体", weight="bold")
4948
elif extra.get("italic"):
50-
tag_font += ("italic",)
49+
tag_font.config(slant="italic")
5150
elif extra.get("strikethrough"):
52-
tag_font += ("overstrike",)
51+
tag_font.config(overstrike=True)
5352

5453
self.tag_configure(tag, font=tag_font, justify=LEFT)
5554
self.insert(END, extra["text"], tag)

0 commit comments

Comments
 (0)