Python Forum
[Tkinter] canvas size
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] canvas size
#1
Hi,
I have an app with a large canvas, showing images.
The canvas is configured:
tifCanvas = Canvas(root, width = 1200, height = 950, relief=RAISED,bg='lightgreen')
tifCanvas.pack(side=LEFT,fill=BOTH,padx=10,pady=10)
I can check this when the app starts by printing:
print('w:',tifCanvas.winfo_reqwidth(),'h:',tifCanvas.winfo_reqheight())
It says : 1204 x 954. OK, so far, so good.
But my monitor is much bigger (1920 x 1200)
When I click (top right) to maximize my app window to fit the monitor,
the canvas clearly gets bigger (fill BOTH), the image stays the same, and when i click a secret button
to print the canvas size at that moment, it slill says: 1204 x 954.
If i can get the correct canvas size at any moment, i could resize my image to be bigger.
But how to find it?
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#2
Maybe this will help
import tkinter as tk

root = tk.Tk()
canvas = tk.Canvas(root, bg='green', width=1200, height=950)
canvas.pack(fill='both', expand = True, padx=10, pady=10)
mytext = canvas.create_text(0, 0, fill='lime', tags=['event'])

def show(event):
    canvas.itemconfigure('event', text=f'Width -> {event.width} Height -> {event.height}')
    xpos = (event.width/2)
    ypos = (event.height/2)
    canvas.coords(mytext, xpos, ypos)
    if event.width > 1210:
        canvas.itemconfigure('event', font=('helvetica 60 bold'))
    else:
        canvas.itemconfigure('event', font=('helvetica 30 normal'))
canvas.bind('<Configure>', show)
root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
Indeed, it does help to show the difference in size.
I found one way to solve the inconvenience by adding:
root.state('zoomed')
So my canvas now always starts with the max size.
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Trying to change font size w/o changing button size python63 3 9,826 Aug-05-2020, 01:04 AM
Last Post: Larz60+
  [Tkinter] Resizing image inside Canvas (with Canvas' resize) Gupi 2 25,083 Jun-04-2019, 05:05 AM
Last Post: Gupi
  PyGtk3 why is Locale Folder Size Half of Module Size ? harun2525 1 3,615 Mar-09-2017, 03:46 AM
Last Post: Analyser

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020