I am trying to create a text widget in Tkinter (for Python), the font size of which can change, but when this happens, I do not want the widget to resize. All text in widgets is the same font style. What I have so far:
root = Tk() t = Toplevel(root) fnt = tkFont.Font(family="Helvetica",size=36,weight="bold",underline=1) txt = Text(t, font=fnt, width=20, height=6) txt.grid(row=0,column=0) b = Button(t, text="click", command=change) b.grid(row=1, column=0) txt.insert(END, "This is text!")
Where change
is defined as:
def change(): txt.delete(1.0, END) fnt.config(size=100) txt.insert(END, "This is text!")
Now, when I press the button, the text really gets bigger, but the whole widget is resized to compensate! I assume that this is because the widget size is specified in terms of โstringsโ and โcharactersโ instead of pixels. How can I stop widget resizing?
I tried not to change the font of the widget, but instead just inserted text with a tag that indicates a new font that works, but then the problem is that when I manually type new text to the left and right of the inserted text, this is the default style, and not the size i want.
source share