tkinterのTextのサンプル
もう平成も終わって令和になりますね。平和な世界になってくれるといいです。 tkinterの本読んでます。
これですね。
tkinterのTextのサンプルです。無かったので書いてみました。
from tkinter import * from tkinter import ttk root = Tk() """ wrapはデフォはNone、選択肢は'char', 'word'です。日本語だとやっぱcharを多用しそうですね。 gridで自動拡張してるので、width, heightはあまり意味ないですね。 TextはStringVarと強調して動けません(仕様)普通に使いにくいですね。改善の余地がありそうです。 getの他に,insert, index, stringで修正、取り出すことができるようです。 """ text = Text(root, wrap='char', width=10, height=4) scroll = Scrollbar(root, orient=VERTICAL, command=text.yview) text['yscrollcommand'] = scroll.set text.grid(row=0, column=0, sticky=(N, W, E, S)) scroll.grid(row=0, column=1, sticky=(N, W, E, S)) button = Button(root, text='print', command=lambda x=None: print(text.get(1.0, 'end'))) button.grid(row=1, column=1) # weightの設定 root.grid_columnconfigure(0, weight=1) root.grid_rowconfigure(0, weight=1) root.mainloop()
そもそもTextで日本語使えないっていうねw ワロタ
追記
import tkinter.font as tkFont root = Tk() customFont = tkFont.Font(family='arial', size=17) content_text = Text(root, font=customFont, width=20, height=4)
これでフォント設定すればいける✋