Adjust a canvas as the window is resized

K

K Viltersten

Do i need to set a callback to a canvas
in order to "listen" to the root window
being resized in order to make it adjust
its contents?

If so, how? If not, how do i make the
canvas draw a line from one corner to
an other?



from Tkinter import *

class Demo(Frame):
def __init__(self, master = None):
Frame.__init__(self, master)
self.grid()
self.doLayout()
master.geometry("800x600")

def doLayout(self):
canvas = Canvas(self, bd = 3, bg = "#93F")
canvas.grid(column = 0, row = 0)
canvas.create_line(0, 0, 100, 200, fill = "#FFF")

def callback(self):
print "callback from canvas"

root = Tk()
demo = Demo(root)
root.mainloop()
 
P

Peter Otten

K said:
Do i need to set a callback to a canvas
in order to "listen" to the root window
being resized in order to make it adjust
its contents?

If so, how? If not, how do i make the
canvas draw a line from one corner to
an other?

import Tkinter as tk

root = tk.Tk()
canvas = tk.Canvas(root)
canvas.pack(expand=True, fill=tk.BOTH)
line = canvas.create_line(0, 0, 0, 0)

def resize(event):
canvas.coords(line, 0, 0, event.width, event.height)
canvas.bind("<Configure>", resize)

root.mainloop()

Peter
 
K

K Viltersten

Do i need to set a callback to a canvas
import Tkinter as tk

root = tk.Tk()
canvas = tk.Canvas(root)
canvas.pack(expand=True, fill=tk.BOTH)
line = canvas.create_line(0, 0, 0, 0)

def resize(event):
canvas.coords(line, 0, 0, event.width, event.height)
canvas.bind("<Configure>", resize)

root.mainloop()


Super nice! Thanks a million!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top