0

Pythonのtkinterボックスでテキストのサイズを変更することは可能ですか? 私はテキストを追加できることを知っており、そうするとき、他の特性の中でフォントサイズを定義します. たとえば、何かがプログラムをトリガーしてテキストのサイズを変更することは可能ですか?

4

1 に答える 1

0

ボックスを使用している場合は、Textタグを使用して内容をフォーマットできます。例えば:

#!/usr/bin/env python

import Tkinter
import tkFont

class App:
    def __init__(self):

        # Set up the text box
        self.root = Tkinter.Tk()
        self.text = Tkinter.Text(self.root, width=20, height=5)
        self.text.insert(Tkinter.INSERT, "Hello...")
        self.text.pack()

        # set up a mouse event
        self.text.bind("<Button-1>", self.click)

        # Set Tkniter's main loop
        self.root.mainloop()

    def click(self, event):
        self.text.tag_add("here", "1.0", "1.4")
        self.text.tag_config("here", background="yellow", font=tkFont.Font(size=36))

if __name__ == "__main__":
    App()

マウスでボックスをクリックすると、入力されたテキストのセクションの背景とサイズが変更されます。

于 2012-10-05T07:04:34.890 に答える