我为我的应用程序制作了一个简单的字体预览器。这在我的Macbook Pro上正常工作,但在我的个人Macbook Pro上却报错。我相信问题是缺少字体。这是打印到终端的错误:
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 45 (X_OpenFont)
Value in failed request: 0x600173
Serial number of failed request: 5292
Current serial number in output stream: 5293
这是出现错误的代码
import Tkinter as tk
import tkFont
import math
class FontPicker(tk.Toplevel):
def __init__(self, parent):
tk.Toplevel.__init__(self, parent)
self.parent = parent
self.title("FontPicker")
fonts = list(tkFont.families())
ROW, COL = 0, 0
for font in fonts:
label = tk.Label(self, text=font, font=(font, 12))
label.grid(row=ROW, column=COL)
label.bind("<Button-1>", lambda event, font=font: self.set_font(font))
ROW += 1
if ROW > 2*math.sqrt(len(fonts)):
ROW = 0
COL += 1
def set_font(self, font):
global popup
popup = tk.Toplevel()
container = tk.Frame(popup)
container.pack()
label = tk.Label(container, text="Select font for")
label.grid(row=0, column=0, columnspan=3, sticky=tk.NSEW)
b1 = tk.Button(container, text="Buttons", command=lambda: self.set_font_buttons(font))
b1.grid(row=1, column=0, sticky=tk.NSEW)
b2 = tk.Button(container, text="Queue", command=lambda: self.set_font_queue(font))
b2.grid(row=1, column=1, sticky=tk.NSEW)
b3 = tk.Button(container, text="Log", command=lambda: self.set_font_log(font))
b3.grid(row=1, column=2, sticky=tk.NSEW)
def set_font_buttons(self, font):
self.parent.parent.master.fontfam_main.set(font)
popup.destroy()
def set_font_queue(self, font):
self.parent.parent.master.fontfam_q.set(font)
popup.destroy()
def set_font_log(self, font):
self.parent.parent.master.fontfam_log.set(font)
popup.destroy()