« Back to profile of nourux

  • Python

    Cross Road

    cross road

    20:24 Aug 05 2010 | Tags :
    						#-*- coding:utf-8 -*-
###############################################
#                                             #
#         Program written by NouruX           #
#               Licence : GPL                 #
#                                             #
###############################################

###############################################
#This program that



###############################################
#Importation of modules
from Tkinter import *


###############################################
#Definition of functions
def change():
    global flag
    if flag%2 == 0 :
        myCan.coords(cercle00, 40, 180, 70, 210)
        myCan.coords(cercle01, 330, 70, 360, 100)
        myCan.coords(cercle10, 40, 70, 70, 100)
        myCan.coords(cercle11, 330, 180, 360, 210)
    elif flag%2 != 0 :
        myCan.coords(cercle00, 40, 70, 70, 100)
        myCan.coords(cercle01, 330, 180, 360, 210)
        myCan.coords(cercle10, 40, 180, 70, 210)
        myCan.coords(cercle11, 330, 70, 360, 100)
    flag+= 1

def passage():
    i, x, y = 0, 85, 100
    while i < 8:
        myCan.create_rectangle(x, y, x+20, y+80, fill='yellow')
        x = x+30
        i+= 1
###############################################
#Main

#Setting a flag
flag = 0
#Creating a main window
myFen = Tk()
#Creating a Canvas
myCan = Canvas(myFen, width=400, height=300, bg='white')
myCan.pack()
#Create the road
myCan.create_rectangle(80, 10, 320, 290, fill='dark gray')
#Create cercles
cercle00 = myCan.create_oval(40, 70, 70, 100, width=2, outline='green', fill='green')
cercle01 = myCan.create_oval(330, 180, 360, 210, width=2, outline='green', fill='green')
cercle10 = myCan.create_oval(40, 180, 70, 210, width=2, outline='red', fill='red')
cercle11 = myCan.create_oval(330, 70, 360, 100, width=2, outline='red', fill='red')

myBtn0 = Button(myFen, text='Change', command=change)
myBtn0.pack(side=RIGHT)


passage()
myFen.mainloop()
    			         

    2 comments

  • anassahmed says :

    لِمَ تستخدم TKinter؟ أراها بشعة حقاً .. فماذا يعجبكـ فيها؟؟

  • karam says :

    وأنا أيضا لا تعجبني واجهات TKinter بشكل كبير PyQt4 ولكن تعجني واجهات جربوها وشوفو الفرق

Add comment
To add a comment, please : Login or Sign up
    nourux
    Noureddine
  • New visitor?

    On setCode, you can save your codes, functions and classes, you can also share them with your friends, and track your favorite developer

    Join the SetCode community
  • Your language here :