Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Python, TKinter, and GUI Canvas

This thread is locked; no one can reply to it. rss feed Print
Python, TKinter, and GUI Canvas
Chris Katko
Member #1,881
January 2002
avatar

I'm playing around with a GUI Canvas with TKinter in Python. I'm very new to GUI design.

I can make a window instance, with a canvas. I can draw lines to it. But I can also draw rectangles and text to it.

Two questions:

1 - Is it possible to put a larger canvas than the window size, and add scroll bars? Something like Logisim.

{"name":"shot-2.7.0.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/0\/508ece8a61caef431e4b29dbcebf9d6a.png","w":471,"h":302,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/0\/508ece8a61caef431e4b29dbcebf9d6a"}shot-2.7.0.png

2 - Drawing say, a rectangle, returns an item id. Does that mean I can hook a callback up to fire when someone clicks on one of those drawn rectangles? Or are canvas's just frame buffers for blindly drawing to? I'm pretty sure in the case of TKinter, this is actually interactive. But I'm not sure how to do a callback function.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

torhu
Member #2,727
September 2002
avatar

A canvas sounds like something you would draw to, not something you would add widgets too. Is that really what you want? Often you would have a regular window with buttons and text fields and stuff, and one of those widgets is a canvas that you draw graphics in.

I have no idea about the callback function, I don't think most GUI libs work like that, though.

Chris Katko
Member #1,881
January 2002
avatar

I think I'm making headway on #2.

A Canvas in TKinter is pretty dang cool. It's a dirty-rectangle stack of objects that all retain their "object" characteristics, as opposed to what I would presume a canvas would be--nothing more than a framebuffer meaning you lose drawing order and any object properties the second you blit. So what I mean is, you can easily change them in real-time, and they can respond to Mouse Over (inheriently) and Clicking events (with binding callbacks).

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

torhu
Member #2,727
September 2002
avatar

Go to: