[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Adjust a canvas as the window is resized

K Viltersten

3/8/2008 8:26:00 PM

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




--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

2 Answers

Peter Otten

3/10/2008 8:44:00 AM

0

K Viltersten wrote:

> 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 Viltersten

3/10/2008 7:12:00 PM

0

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


Super nice! Thanks a million!

--

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy