2017-04-19 171 views
0

如何?我试过的tkinter帆布上的粗体文本

self.textindex = self.canvastext.create_text(0,696,font=('freemono bold',9), anchor='nw', fill='black', text='Longitude: ' + str(px)) 

self.textindex = self.canvastext.create_text(0,696,font=('bold', 'freemono bold',9), anchor='nw', fill='black', text='Longitude: ' + str(px)) 

等几个变化,要么有字体类型恢复到默认字体或给我的错误。

我实际上想要某种类型的字体是块风格的字体,每个字符都有相同的宽度,所以我可以在屏幕的某些部分设置很好的列风格格式。我没有看到我运行的任何程序,Times Roman(我认为这是正确的名称)弹出,所以我猜测Linux Mint不符合标准:)因此使用freemono。我会坚持默认字体,这已经是大胆的,试图在屏幕上格式化它更加困难,虽然我看起来有点不错,但这个程序现在变得很好。

+0

您可以尝试阅读一些文档,而不是尝试随机的东西。 http://effbot.org/tkinterbook/tkinter-widget-styling.htm,http://www.tkdocs.com/tutorial/fonts.html,https://www.tutorialspoint.com/python/tk_fonts.htm, http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/fonts.html –

+0

其实我已经使用Canvas窗口部件effbot.org网页来获取,但我甚至没有想到转到其他页面。我认为我已经按照现在的方式尝试了它,但我不应该一直把引号放在大胆的位置。小愚蠢滑倒。 – confused

回答

0

而不是改变字母的重量,你可以通过说(字体=“Ariel”)来改变字母的字体,但是对于你来说足够厚的字体。希望这有助于:)

3

最好的方法是创建一个字体对象。例如:

# python2 
import Tkinter as tk 
import tkFont as tkfont 

# python3 
# import tkinter as tk 
# from tkinter import font as tkfont 

root = tk.Tk() 
canvas = tk.Canvas(root, width=400, height=400, background="bisque") 
canvas.pack(fill="both", expand=True) 

normal_font = tkfont.Font(family="Helvetica", size=12) 
bold_font = tkfont.Font(family="Helvetica", size=12, weight="bold") 

canvas.create_text(50,50, text="This is normal", font=normal_font) 
canvas.create_text(50,100, text="This is bold", font=bold_font) 

root.mainloop()