Canvas: Simple plot : Canvas « GUI Tk « Python

Home
Python
1.2D
2.Application
3.Buildin Function
4.Class
5.Data Structure
6.Data Type
7.Database
8.Development
9.Dictionary
10.Event
11.Exception
12.File
13.Function
14.GUI Pmw
15.GUI Tk
16.Language Basics
17.List
18.Math
19.Network
20.String
21.System
22.Thread
23.Tuple
24.Utility
25.XML
Perl
Ruby
PHP
Python Tutorial
Python Open Source
Python » GUI Tk » CanvasScreenshots 
Canvas: Simple plot
Canvas: Simple plot

/*

An Introduction to Tkinter
Fredrik Lundh

http://www.pythonware.com/library/tkinter/introduction/

 
Copyright 1999 by Fredrik Lundh
*/





from Tkinter import *

def main():
    root = Tk()
    root.title('Simple Plot - Version - Smoothed')

    try:
        canvas = Canvas(root, width=450, height=300, bg = 'white')
        canvas.pack()
        Button(root, text='Quit', command=root.quit).pack()

        canvas.create_line(100,250,400,250, width=2)
        canvas.create_line(100,250,100,50,  width=2)

        for i in range(11):
            x = 100 (i * 30)
            canvas.create_line(x,250,x,245, width=2)
            canvas.create_text(x,254, text='%d'% (10*i), anchor=N)

        for i in range(6):
            x = 250 (i + 40)
            canvas.create_line(100,y,105,y, width=2)
            canvas.create_text(96,y, text='%5.1f'% (50.*i), anchor=E)

        scaled = []
        for x,y in [(1256)(2094)(3398)(45120)(61180),
                    (75160)(98223)]:
            scaled.append(100 3*x, 250 (4*y)/5)

        canvas.create_line(scaled, fill='black', smooth=1)

        for xs,ys in scaled:
            canvas.create_oval(x-6,y-6,x+6,y+6, width=1,
                               outline='black', fill='SkyBlue2')
    except:
        print 'An error has occured!'

    root.mainloop()

main()

           
       
Related examples in the same category
1.Bound Scale action with a canvasBound Scale action with a canvas
2.Canvas inside a frameCanvas inside a frame
3.Use canvas to draw line, oval, rectangle, bitmap and arc
4.Bind mouse click action to the object on a canvasBind mouse click action to the object on a canvas
5.Bind action to canvasBind action to canvas
6.Use mouse to draw a shape on canvasUse mouse to draw a shape on canvas
7.Image canvasImage canvas
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.