我尝试在Sci-notebook Python应用程序中使用符号按钮。但alpha显示为"^"
symbol = {'alpha':97,'beta':98,'gamma':103,'delta':100,
'epsilon':101,'zeta':122,'eta':104,'theta':113,
..... }
xp=0
yp=0
sym_button=[]
for i in range(len(symbol.items())):
cp=chr(symbol.items()[i][1])
sym_button.append(tk.Button(frame1, width=1, height=1, font='Symbol 9', text=cp))
sym_button[len(sym_button)-1].place(x=840+xp,y=0+yp)
xp=xp+17
if xp+840>960:
xp=0
yp=yp+25
我需要尝试类似于"What?"
cp=chr(symbol.items()[i][1]).encode('Symbol')
LookupError: unknow encoding: Symbol
依靠一种特殊的字体来产生这些符号可能不是最好的方法。相反,您应该考虑直接使用各自的unicode字符。您可以找到字符代码,例如,在维基百科页面上alpha, beta等。
最小的例子:
root = tk.Tk()
symbol = {'alpha':945, 'beta':946, 'gamma': 947, 'delta': 948, 'epsilon':949}
for s in symbol:
tk.Button(root, text=unichr(symbol[s])).pack()
root.mainloop()