python3のGUIのTkinterの利用方法について調べています。
その中で、ListBoxの位置を中央に配置する方法がわかりません。
以下のソース(tk_sample.py)で、
lb.grid(row=0, column=5)
のrowの値を変更すれば中央に配置できると思ったのですが、
うまく行きません。
ご教授をお願いできないでしょうか。よろしくお願いします。
// tk_sample.py
import tkinter as tk entry = None response_area = None lb = None action = None def putlog(str): lb.insert(tk.END, str) def prompt(): p = "テスト" if (action.get()) == 0: p += ':' + "テスト" return p + '> ' def talk(): value = entry.get() if not value: response_area.configure(text='なに?') else: response_area.configure(text="テスト") putlog('> ' + value) putlog(prompt() + "テスト") entry.delete(0, tk.END) def run(): global entry, response_area, lb, action root = tk.Tk() root.geometry('880x560') root.title('Intelligent Agent : ') font = ('Helevetica', 14) font_log = ('Helevetica', 11) menubar = tk.Menu(root) root.config(menu=menubar) filemenu = tk.Menu(menubar) menubar.add_cascade(label='ファイル', menu=filemenu) filemenu.add_command(label='閉じる', command=root.destroy) action = tk.IntVar() optionmenu = tk.Menu(menubar) menubar.add_cascade(label='オプション', menu=optionmenu) optionmenu.add_radiobutton( label='Responderを表示', variable=action, value=0 ) optionmenu.add_radiobutton( label='Responderを表示しない', variable=action, value=1 ) frame = tk.Frame( root, relief=tk.RIDGE, borderwidth=4 ) entry = tk.Entry( frame, width=70, font=font ) entry.pack(side=tk.LEFT) entry.focus_set() # ボタンの作成 button = tk.Button( frame, width=15, text='話す', command=talk ) button.pack(side=tk.LEFT) frame.place(x=30, y=520) lb = tk.Listbox( root, width=42, height=30, font=font_log ) sb1 = tk.Scrollbar( root, orient=tk.VERTICAL, command=lb.yview ) sb2 = tk.Scrollbar( root, orient=tk.HORIZONTAL, command=lb.xview ) lb.configure(yscrollcommand=sb1.set) lb.configure(xscrollcommand=sb2.set) lb.grid(row=0, column=5) sb1.grid(row=0, column=1, sticky=tk.NS) sb2.grid(row=1, column=0, sticky=tk.EW) root.mainloop() if __name__ == '__main__': run()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/06 22:19