IPB

Bienvenue invité ( Connexion | Inscription )

[ En ligne ] · Standard · Linéaire+

> Momo Se Remet à La "programmation", Sponsorised by O'Reilly

momo
post 21/02/2004 1:21
Message #1


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



CODE
from Tkinter import *
def printit(event):
   words=dict([("..--..","?"),("--..--",","),(".-.-.-","."),("----.","9"),("---..","8"),
           ("--...","7"), ("-....","6"), (".....","5"), ("....-","4"), ("...--","3"),
           ("..---","2"), (".----","1"), ("-----","0"), ("--..","z"), ("-.--","y"),
           ("-..-","x"), ("...-","v"), ("--.-","q"), (".---","j"), ("....","h"),
           ("..-.","f"), ("-.-.","c"), ("-...","b"), (".--.","p"), ("..-", "u"), ("...","s"),
           (".-.","r"), ("---","o"), ("-.-","k"), ("--.","g"), ("-..","d"),
           ("-.","n"), ("..","i"), ("--","m"), (".-","a"), (".","e"), ("-","t"),
           (".-..","l"), (".--","w")])
   fichier=unicode(ent.get())
   sfichier=""
   caractere="0"
   counter=0
   while caractere<>"":
       if counter<int(len(fichier)):
           caractere=fichier[counter]
       else:
           caractere=""
       counter=counter+1
       chaine =""
       while ( caractere=="." or caractere=="-"):
           chaine=chaine+caractere
           if counter<int(len(fichier)):
               caractere=fichier[counter]
           else:
               caractere=""
           counter=counter+1
       if words.has_key(chaine):
           schaine=words[chaine]
           chaine=""
           caractere="."
           sfichier=sfichier+unicode(schaine)
       else:
           sfichier=sfichier+unicode(chaine)
           chaine=""

       if (caractere=="." or caractere=="-"):
           caractere="0"
       else:
           sfichier=sfichier+unicode(caractere)
   lab.configure(text=unicode(sfichier))

fen=Tk()
ent=Entry(fen)
lab=Label(fen)
ent.bind("<Return>",printit)
ent.pack()
lab.pack()
fen.mainloop()

Ben ouais, m'ennuyant, je me suis acheté "Apprendre à programmer avec Python" et "Python Précis et concis" (non, pas seulement pour avoir le sadisme de mettre le python en présence de la mangouste wink.gif).
Et comme j'ai toujours ce programme @ la con de decodage de code Morse qui traine ...


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
 
Reply to this topicStart new topicStart Poll
Réponse(s)
momo
post 02/03/2004 16:06
Message #2


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



et hop :
CODE

# -*- coding: Latin-1 -*-
from Tkinter import *
# Definition des classes à utiliser :
class Cercle(Canvas):
   def __init__(self,boss=None,larg=200,haut=200):
       Canvas.__init__(self)
       self.configure(width=larg,height=haut)
       self.larg,self.haut=larg,haut

   def traceCercle(self, taille=5, coul="red"):
       posx,posy=(self.larg/2)-taille,(self.haut/2)-taille
       taix,taiy=posx+2*taille,posy+2*taille
       n=self.create_oval(posx,posy,taix,taiy,outline=coul,fill=coul)
       return n

class ChoixTaille(Frame):
   def __init__(self, boss=None):
       Frame.__init__(self)
       self.taille=5
       Scale(self, length=150, orient=HORIZONTAL,sliderlength=25,\
             label="Taille du cercle", from_=5, to_=100,tickinterval=15,\
             resolution=1,showvalue=1,command=self.setTaille).pack()
   def setTaille(self,f):
       self.taille=int(f)
       self.event_generate('<Control-Z>')
   def getTaille(self):
       n=self.taille
       return n
#definition de la fenêtre principale
class TailleCercle(Frame):
   def __init__(self,boss=None):
       Frame.__init__(self)
       self.gra=Cercle(self,larg=400,haut=400)
       self.gra.configure(bg="black")
       self.gra.pack(side=TOP)
       self.cercle=""
       self.controle=ChoixTaille(self)
       self.controle.pack()
       self.master.bind("<Control-Z>",self.montreCercle)
       self.master.title("Variation de taille d'un cercle")
       self.pack()
   def montreCercle(self,event):
       self.gra.delete(self.cercle)
       self.cercle=self.gra.traceCercle(taille=int(self.controle.getTaille()),coul="White")
#programme principal
if __name__=="__main__":
   TailleCercle().mainloop()

m'enfin, c'est marrant : autant en java le concept de classe me fait chier, autant en python, je trouve ça simple et élégant ...
rq : c'est peut être parceque le langage me laisse le choix ... et me permet de passer à du code objet progressivement ...
m'enfin, y a pas à dire mais le bouquin est bien fait ...


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Posts in this topic


Reply to this topicTopic OptionsStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :
 

Version bas débit Nous sommes le : : 17/11/2025 8:43