tkinterのラベルの文字を左詰に表示する方法が分からりません。
google検索してみると、'justify'というオプションで'left'を指定する旨いくつかのサイトに書いてあるのですが、以下のmesという引数で受けたテキストをラベルに表示するコードでどうしても、テキストが中央揃えになってしまいます。左詰に表示したいのですが、どうしたらいいでしょう?
Python
1import tkinter 2import os 3def QuestionBox (mes, filename="none", x=50, y=50, width=900, height=150, title="Question", 4 workdir="C:\temp"): 5 result = None 6 # Tkクラス生成 7 root = tkinter.Tk() 8 root.geometry('{}x{}+{}+{}'.format(width, height, x, y)) 9 root.title(title) 10 root.attributes("-topmost", True) 11 root.option_add('*font', (u'MS ゴシック', 20)) 12 13 # ラベル 14 lbl = tkinter.Label(text=mes) 15 lbl.place(x=30, y=10) 16 lbl.option_add('*justify', ('left')) 17 # lbl.option_add('justify','left') 18 19 20 # テキストボックス 21 # txt = tkinter.Entry(width=7, font="u'MS ゴシック', 20, 'bold'", title="Question") 22 txt = tkinter.Entry(width=7) 23 txt.option_add('*font', (u'MS ゴシック', 20, 'bold')) 24 25 26 txt.place(x=1150, y=15) 27 txt.pack(padx=5, pady=5, anchor=tkinter.SE) 28 # txt.insert(tkinter.END, "3") 29 30 def FlagWright(): 31 nonlocal result 32 num = txt.get() 33 if filename != "none": 34 pathstring = os.path.join(workdir,filename) 35 with open(pathstring, 'w', encoding='utf-8') as file: 36 file.write(num) 37 result = num 38 root.quit() 39 40 # button1 = tkinter.Button(root, text='決定', command=lambda: make_cmd(root), 41 button1 = tkinter.Button(root, text='決定', width=10, height=2, command=lambda :FlagWright()) 42 button1.pack(side=tkinter.BOTTOM, padx=5, pady=5, anchor=tkinter.SE) 43 44 root.mainloop() 45 # num = txt.get() 46 root.quit() 47 return result 48

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/27 11:30
2018/11/27 23:19
2018/11/27 23:21 編集
2018/11/28 01:01 編集
2018/11/28 01:06
2018/11/28 01:27 編集