Is it possible to resize text in a tkinter box in python? I know I can add text and, when doing so, among other traits, define the font size. Is it possible to resize the text if say, something triggers the program to do so?
If you are using a Text
box you can use tags for formatting its contents. For instance:
#!/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()
will change the background and size of a section of the entered text when you click the box with your mouse.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.