473,503 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tkinter canvas mvc

Hi all!

I have just finished my tkinter text editor, learning tkinter purpose.

Now I want to learn canvas so I want to make my paint program, I think that this
will be the best to do over model-view-controler pattern which I need to learn also.

Is there any good tutorial for mvc in python or can someone explain me little
bit about mvc?
or maybe some code snippet in mvc, that will be nice.

Thanks in advance!

Apr 5 '07 #1
1 2423
Gigs_ wrote:
Hi all!

I have just finished my tkinter text editor, learning tkinter purpose.

Now I want to learn canvas so I want to make my paint program, I think
that this will be the best to do over model-view-controler pattern which
I need to learn also.

Is there any good tutorial for mvc in python or can someone explain me
little bit about mvc?
or maybe some code snippet in mvc, that will be nice.

Thanks in advance!
MVC in a nutshell.

1. You need a model.
2. You need a view.
3. You need a controller.

Lets see how they work together, using dictionary-like interfaces:
class Model(dict): pass

class View(object):
def __init__(self, controller, keys):
self.controller = controller
self.widgets = {}
for k in keys:
w = make_a_widget(k)
def _callback(w=w):
v = w.get_value()
self.controller[k] = v
w.bind(SomeEvent, _callback)
self.widgets[k] = w
self.controller.register_view(self)
def __setitem__(self, k, v):
self.widgets[k].set_value(v)
def __contains__(self, k):
return k in self.widgets

class Controller(object):
def __init__(self, model):
self.views = []
self.data = model
def register_view(self, aview):
self.views.append(aview)
def __setitem__(self, k, v):
self.data[k] = v
for aview in self.views:
if k in aview:
aview[k] = v
def __getitem__(self, k):
return self.data[k]
def update(self, adict):
self.data.update(adict)
for k,v in adict.items():
for aview in self.views:
if k in aview:
aview[k] = v

James
Apr 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3994
by: mksql | last post by:
New to Tkinter. Initially, I had some code that was executing button commands at creation, rather than waiting for user action. Some research here gave me a solution, but I am not sure why the...
1
10431
by: Elaine Jackson | last post by:
Newbie. Playing with the 'turtle' module and wondering if there's a way to save the graphics you make with it. The documentation itself has nothing to say about this, nor (as far as I can tell)...
1
2952
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
0
3565
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust...
3
4464
by: Tuvas | last post by:
I'm trying to display a picture on a Tkinter Canvas. It seems to work fine the first time that it is displayed. However, subsequent times running shows an error like this: TCLerror: Wrong #...
5
14894
by: Dean Allen Provins | last post by:
I need to determine the size of a canvas while the process is running. Does anyone know of a technique that will let me do that? Thanks, Dean
4
2860
by: Davy | last post by:
Hi all, I have written a simple Tkinter program, that is draw a rectangle in a canvas, when I press Up key, the rectangle move up. But the program seems work not properly? My environment is...
4
9117
by: skanemupp | last post by:
mapq = PhotoImage(file = 'C:\Users\saftarn\Desktop\elmapovic.gif') w.create_image(10, 10, image = mapq, anchor = NW) after doing this is there any possibility of getting the characteristics of...
7
4691
by: Peter Pearson | last post by:
Tkinter makes it very easy to drag jpeg images around on a canvas, but I would like to have a "target" change color when the cursor dragging an image passes over it. I seem to be blocked by the...
3
2958
by: joshdw4 | last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes, it's that pesky root window and I have tried withdraw to no avail. I'm assuming this is because of the methods I'm using. I...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.