2017-08-12 14 views
1

フォントファミリを変更したいが、機能しません。Tkinterはフォントファミリを変更しません

from tkinter import * 
import tkinter.font as font 

class Window: 

    def __init__(self): 
     root = Tk() 
     def_font=font.Font(family='Times') 
     root.title("Serial Conection Program") 

     self.mainFrame= Frame(root) 

     self.portLabel=Label(self.mainFrame, text="Port: ",font= def_font) 
    .... 
    .... 

(私はのpython 3.6.1-anaconda3を使用)インタプリタとたぶんいくつかの問題私は、通常のfont= 'Times'ような何かをしようとしていたが、これはまた、動作しません...

There is an image(I tried to change font in label "connection" to family "Times"

+0

あなたはそれが機能していないことをどのように知っていますか?エラーが出ていますか? –

+0

このコードではエラーは発生しませんが、fonstは変更されません(サイズ変更のみ可能)。 –

+0

そのスクリーンショットに基づいて、tkinterはシステム上にフォントを見つけられていないように見え、ビットマップフォントに戻っています。フォントを作成した後、次のコード行をプログラムに追加すると、何が得られますか? 'print(def_font.actual())' –

答えて

0

どのように正確にそれが動作しませんか?あなたはスクリーンショットで見ることができるよう、次は(Pythonの3.6.2を使用して)私のために行います。

from tkinter import * 
import tkinter.font as font 

class Window: 
    def __init__(self): 
     root = Tk() 
     #print(font.families()) # print list of what's available 
     root.title("Serial Connection Program") 

     self.mainFrame = Frame(root) 
     self.mainFrame.pack() 

     def_font=font.Font(family='Times') 
     self.portLabel = Label(self.mainFrame, text="Port1: ", font=def_font) 
     self.portLabel.pack() 

     my_font=font.Font(family='Arial') 
     self.portLabel = Label(self.mainFrame, text="Port2: ", font=my_font) 
     self.portLabel.pack() 

     root.mainloop() 

win = Window() 

screenshot of tkinter window with buttons with two different fonts

0

私はRaspbian OSで同様の問題がありました。

「コードボールド」を「コードボールド」に変更しました。だからあなたのために、Times - > timesを変えてみてください。

関連する問題