简体   繁体   中英

How do I set the Text in tkinter size to the size of the main window?

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!

text_area.place(x = 0, y = 0)

  • I Guess Try to Put Your value Try to refer docs *

  • docs can be founded here

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()

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM