Reputation: 846
I had created a text area in tkinter and I want its size to fit the Tk() each time I resize the window!
This is my Code:
from tkinter import *
#The window:
app = Tk()
#The size of the screen:
s_width = app.winfo_screenwidth()
s_height = app.winfo_screenheight()
#The text area:
text_area = Text(app, width = s_width, height = s_height)
text_area.place(x = 0, y = 0)
#mainloop
app.mainloop()
But this gives a weird size to the text_area!
I want the text_area to be at the size of the app variable!
How can I do it?
It should resize every time I resize the screen!
Upvotes: 0
Views: 1021
Reputation: 46669
You created a very big Text
box as you used the screen resolution as the width and height of the text box. Note that width
and height
options of Text
widget are in characters, not pixels. So for a screen resolution of 1920x1080
, then you created a Text
box with 1920 characters width and 1080 lines height.
To make the text box resize along with the root window, you can use relwidth
and relheight
options of place()
:
from tkinter import *
#The window:
app = Tk()
#The text area:
text_area = Text(app)
text_area.place(x=0, y=0, relwidth=1, relheight=1)
#mainloop
app.mainloop()
Upvotes: 1
Reputation: 140
text_area.place(x = 0, y = 0)
I Guess Try to Put Your value Try to refer docs *
docs can be founded here
Upvotes: 1