issue51:python_partie_25_pp._7-14
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue51:python_partie_25_pp._7-14 [2011/08/15 15:51] – fredphil91 | issue51:python_partie_25_pp._7-14 [2011/08/31 21:35] (Version actuelle) – fredphil91 | ||
---|---|---|---|
Ligne 2: | Ligne 2: | ||
PLEASE NOTE – All of the code presented here is for Python 2.x only. In an upcoming article, we'll discuss how to use tkinter in Python 3.x. If you MUST use Python 3.x, change the import statements to “from tkinter import *”.** | PLEASE NOTE – All of the code presented here is for Python 2.x only. In an upcoming article, we'll discuss how to use tkinter in Python 3.x. If you MUST use Python 3.x, change the import statements to “from tkinter import *”.** | ||
- | Un certain nombre d' | + | Un certain nombre d' |
- | NOTE - Tout le code présenté ici est pour Python 2.x seulement. Dans un prochain article, nous allons discuter de la façon d' | + | NOTE : Tout le code présenté ici est pour Python 2.x seulement. Dans un prochain article, nous allons discuter de la façon d' |
**A Little History And A Bit Of Background | **A Little History And A Bit Of Background | ||
Ligne 11: | Ligne 11: | ||
Basically, we have the Toplevel container widget which contains (holds) other widgets. This is the root or master window. Within this root window, we place the widgets we want to use within our program. Each widget, other than the Toplevel root widget container, has a parent. The parent doesn' | Basically, we have the Toplevel container widget which contains (holds) other widgets. This is the root or master window. Within this root window, we place the widgets we want to use within our program. Each widget, other than the Toplevel root widget container, has a parent. The parent doesn' | ||
- | Un peu d' | + | Un peu d' |
- | Tkinter est synonyme | + | Tkinter est l' |
- | Fondamentalement, | + | Fondamentalement, |
**In order to place and display the child widgets, we have to use what's called “geometry management”. It's how things get put into the main root window. Most programmers use one of three types of geometry management, either Packer, Grid, or Place management. In my humble opinion, the Packer method is very clumsy. I'll let you dig into that on your own. The Place management method allows for extremely accurate placement of the widgets, but can be complicated. We'll discuss the Place method in a future article set. For this time, we'll concentrate on the Grid method. | **In order to place and display the child widgets, we have to use what's called “geometry management”. It's how things get put into the main root window. Most programmers use one of three types of geometry management, either Packer, Grid, or Place management. In my humble opinion, the Packer method is very clumsy. I'll let you dig into that on your own. The Place management method allows for extremely accurate placement of the widgets, but can be complicated. We'll discuss the Place method in a future article set. For this time, we'll concentrate on the Grid method. | ||
Ligne 22: | Ligne 22: | ||
So parent has the grid, the widgets go into the grid positions. At first glance, you might think that this is very limiting. However, widgets can span multiple grid positions in either the column direction, the row direction, or both.** | So parent has the grid, the widgets go into the grid positions. At first glance, you might think that this is very limiting. However, widgets can span multiple grid positions in either the column direction, the row direction, or both.** | ||
- | Afin de placer et d' | + | Afin de placer et d' |
- | Pensez à un tableur. Il y a des rangées | + | Pensez à un tableur. Il y a des lignes |
Le parent possède la grille, les widgets vont dans les positions de la grille. Au premier regard, vous pourriez penser que cela est très limitatif. Toutefois, les widgets peuvent s' | Le parent possède la grille, les widgets vont dans les positions de la grille. Au premier regard, vous pourriez penser que cela est très limitatif. Toutefois, les widgets peuvent s' | ||
Ligne 45: | Ligne 45: | ||
Notre premier exemple | Notre premier exemple | ||
- | Notre premier exemple est SUPER simple (seulement quatre lignes), mais montre un bon peu. | + | Notre premier exemple est SUPER simple (seulement quatre lignes), mais explicite. |
from Tkinter import * | from Tkinter import * | ||
Ligne 70: | Ligne 70: | ||
Nous créons un bouton appelé bouton, définissons son parent à la fenêtre racine, réglons son texte à « Bonjour FullCircle » et le plaçons dans la grille. Enfin, nous appelons la boucle principale de la fenêtre. Ça paraît très simple quand on regarde le code, mais beaucoup de choses se passent dans les coulisses. Heureusement, | Nous créons un bouton appelé bouton, définissons son parent à la fenêtre racine, réglons son texte à « Bonjour FullCircle » et le plaçons dans la grille. Enfin, nous appelons la boucle principale de la fenêtre. Ça paraît très simple quand on regarde le code, mais beaucoup de choses se passent dans les coulisses. Heureusement, | ||
- | Exécutez le programme et nous allons voir ce qui se passe. Sur ma machine, la fenêtre principale apparaît en bas à gauche de l' | + | Exécutez le programme et nous allons voir ce qui se passe. Sur ma machine, la fenêtre principale apparaît en bas à gauche de l' |
Notre deuxième exemple | Notre deuxième exemple | ||
Ligne 115: | Ligne 115: | ||
self.btnQuit.grid(column = 1, row = 1)** | self.btnQuit.grid(column = 1, row = 1)** | ||
+ | Nous nommons les widgets, fixons leur parent (cadre) et définissons le texte à afficher. Maintenant btnQuitter a un attribut marqué fg que nous avons réglé à « red ». Vous avez deviné que cela définit la couleur d' | ||
+ | Nous devons placer nos widgets dans la grille. Voici les lignes à nouveau : | ||
+ | |||
+ | cadre.grid(column = 0, row = 0) | ||
+ | | ||
+ | self.lblTexte.grid(column = 0, row = 0, columnspan = 2) | ||
+ | | ||
+ | self.btnBonjour.grid(column = 0, row = 1) | ||
+ | | ||
+ | self.btnQuitter.grid(column = 1, row = 1) | ||
**First, we assign a grid to the frame. Next, we set the grid attribute of each widget to where we want the widget to go. Notice the columnspan line for the label (self.lblText). This says that we want the label to span across two grid columns. Since we have only two columns, that's the entire width of the application. Now we can create our callback function: | **First, we assign a grid to the frame. Next, we set the grid attribute of each widget to where we want the widget to go. Notice the columnspan line for the label (self.lblText). This says that we want the label to span across two grid columns. Since we have only two columns, that's the entire width of the application. Now we can create our callback function: | ||
Ligne 132: | Ligne 142: | ||
root.mainloop()** | root.mainloop()** | ||
+ | Tout d' | ||
+ | def DitUnTruc(self): | ||
+ | print " | ||
+ | |||
+ | Cela affiche simplement dans la fenêtre du terminal le message " | ||
+ | Enfin, on instancie la classe Tk - notre classe App - et exécutons la boucle principale. | ||
+ | |||
+ | racine = Tk() | ||
+ | app = App(racine) | ||
+ | racine.mainloop() | ||
**Give it a try. Now things actually do something. But again, the window position is very inconvenient. Let's fix that in our next example. | **Give it a try. Now things actually do something. But again, the window position is very inconvenient. Let's fix that in our next example. | ||
Ligne 148: | Ligne 168: | ||
root.mainloop()** | root.mainloop()** | ||
+ | Essayez le programme. Maintenant, il fait vraiment quelque chose. Mais là encore, la position de la fenêtre est très gênante. Corrigeons cela dans notre prochain exemple. | ||
+ | Notre troisième exemple | ||
+ | |||
+ | Enregistrez l' | ||
+ | |||
+ | racine = Tk() | ||
+ | racine.geometry(' | ||
+ | app = App(racine) | ||
+ | racine.mainloop() | ||
**What this does is force our initial window to be 150 pixels wide and 75 pixels high. We also want the upper left corner of the window to be placed at X-pixel position 550 (right and left) and the Y-pixel position at 150 (top to botton). How did I come up with these numbers? I started with some reasonable values and tweaked them from there. It's a bit of a pain in the neck to do it this way, but the results are better than not doing it at all. | **What this does is force our initial window to be 150 pixels wide and 75 pixels high. We also want the upper left corner of the window to be placed at X-pixel position 550 (right and left) and the Y-pixel position at 150 (top to botton). How did I come up with these numbers? I started with some reasonable values and tweaked them from there. It's a bit of a pain in the neck to do it this way, but the results are better than not doing it at all. | ||
Ligne 160: | Ligne 189: | ||
Outside of the geometry statement, this (left) should be pretty easy for you to understand by now. Remember, pick some reasonable values, tweak them, and then move on.** | Outside of the geometry statement, this (left) should be pretty easy for you to understand by now. Remember, pick some reasonable values, tweak them, and then move on.** | ||
+ | Ceci force notre fenêtre initiale à une taille de 150 pixels de large sur 75 pixels de haut. Nous voulons aussi que le coin supérieur gauche de la fenêtre soit placé à une position horizontale de 550 pixels (depuis la droite) et à une position verticale de 150 pixels (depuis le haut). Comment suis-je arrivé à ces chiffres ? J'ai commencé avec des valeurs raisonnables et les ai peaufiné à partir de là. C'est un peu difficile de faire de cette façon, mais les résultats sont meilleurs que si on ne fait rien du tout. | ||
+ | Notre Quatrième exemple - Une calculatrice simple | ||
+ | |||
+ | Maintenant, regardons quelque chose d'un peu plus compliqué. Cette fois, nous allons créer une calculatrice simple à 4 boutons, pour les 4 opérations : addition, soustraction, | ||
+ | |||
+ | Nous allons y plonger tout de suite et je vous expliquerai le code (au milieu à droite) au fur et à mesure. | ||
+ | |||
+ | À part la déclaration de la géométrie, | ||
**We begin our class definition and set up our __init__ function. We set up three variables as follows: | **We begin our class definition and set up our __init__ function. We set up three variables as follows: | ||
Ligne 169: | Ligne 206: | ||
Next, we define the CurrentDisplay variable and assign it to the StringVar object. This is a special object that is part of the Tkinter toolkit. Whatever widget you assign this to automatically updates the value within the widget. In this case, we will be using this to hold whatever we want the display label widget to... er... well... display. We have to instantiate it before we can assign it to the widget. Then we use the built in ' | Next, we define the CurrentDisplay variable and assign it to the StringVar object. This is a special object that is part of the Tkinter toolkit. Whatever widget you assign this to automatically updates the value within the widget. In this case, we will be using this to hold whatever we want the display label widget to... er... well... display. We have to instantiate it before we can assign it to the widget. Then we use the built in ' | ||
+ | Nous commençons notre définition de la classe en mettant en place notre fonction < | ||
+ | • ValeurCourante - Contient la valeur actuelle qui a été entrée dans la calculatrice. | ||
+ | |||
+ | • ValeurAncienne - Contient la valeur qui existait avant que l' | ||
+ | |||
+ | • FonctionCourante - C'est tout simplement pour se souvenir quelle fonction est traitée. | ||
+ | |||
+ | Ensuite, nous définissons la variable AffichageCourant et l' | ||
**def DefineWidgets(self, | **def DefineWidgets(self, | ||
Ligne 177: | Ligne 222: | ||
Now, we have already defined a label earlier. However, this time we are adding a number of other attributes. Notice that we aren't using the ' | Now, we have already defined a label earlier. However, this time we are adding a number of other attributes. Notice that we aren't using the ' | ||
+ | def DefinirWidgets(self, | ||
+ | self.lblAffichage = Label(principale, | ||
+ | Bon, nous avons déjà défini un label auparavant. Cependant, cette fois, nous ajoutons un certain nombre d' | ||
**Next, we set the relief or visual style of the label. The “legal” options here are FLAT, SUNKEN, RAISED, GROOVE, and RIDGE. The default is FLAT if you don't specify anything. Feel free to try the other combinations on your own after we're done. Next, we set the background (bg) to white in order to set it off from the rest of the window a bit. We set the height to 2 (which is two text lines high, not in pixels), and finally assign the variable we just defined a moment ago (self.CurrentDisplay) to the textvariable attribute. Whenever the value of self.CurrentDisplay changes, the label will change its text to match automatically. | **Next, we set the relief or visual style of the label. The “legal” options here are FLAT, SUNKEN, RAISED, GROOVE, and RIDGE. The default is FLAT if you don't specify anything. Feel free to try the other combinations on your own after we're done. Next, we set the background (bg) to white in order to set it off from the rest of the window a bit. We set the height to 2 (which is two text lines high, not in pixels), and finally assign the variable we just defined a moment ago (self.CurrentDisplay) to the textvariable attribute. Whenever the value of self.CurrentDisplay changes, the label will change its text to match automatically. | ||
Ligne 185: | Ligne 233: | ||
I've shown only 4 buttons here. That's because, as you can see, the code is almost exactly the same. Again, we've created buttons earlier in this tutor, but let's take a closer look at what we are doing here.** | I've shown only 4 buttons here. That's because, as you can see, the code is almost exactly the same. Again, we've created buttons earlier in this tutor, but let's take a closer look at what we are doing here.** | ||
+ | Ensuite, nous réglons le relief, qui est le style visuel de l' | ||
+ | |||
+ | Ci-dessus, nous allons créer quelques-uns des boutons. | ||
+ | J'ai montré seulement 4 boutons ici. C'est parce que, comme vous pouvez le voir, le code est presque exactement le même. Encore une fois, nous avons créé des boutons plus tôt dans ce tutoriel, mais nous allons regarder de plus près ce que nous faisons ici. | ||
**We start by defining the parent (master), the text that we want on the button, and the width and height. Notice that the width is in characters and the height is in text lines. If you were doing a graphic in the button, you would use pixels to define the height and width. This can become a bit confusing until you get your head firmly wrapped around it. Next, we are setting the bind attribute. When we did the buttons in the previous examples, we used the ' | **We start by defining the parent (master), the text that we want on the button, and the width and height. Notice that the width is in characters and the height is in text lines. If you were doing a graphic in the button, you would use pixels to define the height and width. This can become a bit confusing until you get your head firmly wrapped around it. Next, we are setting the bind attribute. When we did the buttons in the previous examples, we used the ' | ||
Ligne 191: | Ligne 243: | ||
In Python, we use Lambda to define anonymous functions that will appear to interpreter as a valid statement. This allows us to put multiple segments into a single line of code. Think of it as a mini function. In this case, we are setting up the name of the callback function and the value we want to send as well as the event tag (e:). We'll talk more about Lambda in a later article. For now, just follow the example.** | In Python, we use Lambda to define anonymous functions that will appear to interpreter as a valid statement. This allows us to put multiple segments into a single line of code. Think of it as a mini function. In this case, we are setting up the name of the callback function and the value we want to send as well as the event tag (e:). We'll talk more about Lambda in a later article. For now, just follow the example.** | ||
- | + | Nous commençons par définir le parent (la fenêtre principale), | |
+ | |||
+ | En Python, nous utilisons Lambda pour définir des fonctions anonymes qui apparaîtront à l' | ||
**I've given you the first four buttons. Copy and paste the above code for buttons 5 through 9 and button 0. They are all the same with the exception of the button name and the value we send the callback. Next steps are shown right. | **I've given you the first four buttons. Copy and paste the above code for buttons 5 through 9 and button 0. They are all the same with the exception of the button name and the value we send the callback. Next steps are shown right. | ||
Ligne 201: | Ligne 255: | ||
Let's say the user wants to enter 563 + 127 and get the answer. They will press or click (logically) 5, then 6, then 3, then the “+,” then 1, then 2, then 7, then the “=” buttons. How do we handle this in code? We have already set the callbacks for the number buttons to the funcNumButton function. There' | Let's say the user wants to enter 563 + 127 and get the answer. They will press or click (logically) 5, then 6, then 3, then the “+,” then 1, then 2, then 7, then the “=” buttons. How do we handle this in code? We have already set the callbacks for the number buttons to the funcNumButton function. There' | ||
+ | Je vous ai donné les quatre premiers boutons. Copiez et collez le code ci-dessus pour les boutons de 5 à 9 et pour le bouton 0. Ils sont tous identiques, à l' | ||
+ | |||
+ | La seule chose dont nous n' | ||
+ | |||
+ | Avant d' | ||
+ | Disons que l' | ||
**User clicks 5 – 0 * 10 + 5 (5) | **User clicks 5 – 0 * 10 + 5 (5) | ||
Ligne 215: | Ligne 275: | ||
Above is the code to start defining our callbacks.** | Above is the code to start defining our callbacks.** | ||
+ | L' | ||
+ | L' | ||
+ | |||
+ | L' | ||
+ | |||
+ | Bien sûr, nous devons ensuite afficher la variable « self.ValeurCourante » dans l' | ||
+ | |||
+ | Ensuite, l' | ||
+ | |||
+ | Ci-dessus, voici le code pour commencer à définir nos fonctions de rappel. | ||
**The “funcNumButton routine receives the value we passed from the button press. The only thing that is different from the example above is what if the user pressed the decimal button (“.”). Below, you'll see that we use a boolean variable to hold the fact they pressed the decimal button, and, on the next click, we deal with it. That's what the “if self.DecimalNext == True:” line is all about. Let's walk through it. | **The “funcNumButton routine receives the value we passed from the button press. The only thing that is different from the example above is what if the user pressed the decimal button (“.”). Below, you'll see that we use a boolean variable to hold the fact they pressed the decimal button, and, on the next click, we deal with it. That's what the “if self.DecimalNext == True:” line is all about. Let's walk through it. | ||
- | The user clicks 3, then 2, then the decimal, then 4, to create “32.4”. We handle the 3 and 2 clicks through the “funcNumButton” routine. We check to see if self.DecimalNext is True (which in this case it isn't until the user clicks the “.” button). If not, we simply multiply the held value (self.CurrentValue) by 10 and add the incoming value. When the user clicks the “.”, the callback “funcFuncButton” is called with the “Dec” value. All we do is set the boolean variable “self.DecimalNext” to True. When the user clicks the 4, we will test the “self.DecimalNext” value and, since it's true, we play some magic. First, we increment the self.DecimalCount variable. This tells us how many decimal places we are working with. We then take the incoming value, multiply it by (10< | + | The user clicks 3, then 2, then the decimal, then 4, to create “32.4”. We handle the 3 and 2 clicks through the “funcNumButton” routine. We check to see if self.DecimalNext is True (which in this case it isn't until the user clicks the “.” button). If not, we simply multiply the held value (self.CurrentValue) by 10 and add the incoming value. When the user clicks the “.”, the callback “funcFuncButton” is called with the “Dec” value. All we do is set the boolean variable “self.DecimalNext” to True. When the user clicks the 4, we will test the “self.DecimalNext” value and, since it's true, we play some magic. First, we increment the self.DecimalCount variable. This tells us how many decimal places we are working with. We then take the incoming value, multiply it by (10< |
+ | La routine « foncBoutonNumerique » reçoit la valeur que nous lui passons en appuyant sur un bouton. La seule chose qui diffère de l' | ||
+ | L' | ||
**The “funcClear” routine simply clears the two holding variables, then sets the display. | **The “funcClear” routine simply clears the two holding variables, then sets the display. | ||
Ligne 235: | Ligne 307: | ||
Now the functions. We've already discussed what happens with the function ' | Now the functions. We've already discussed what happens with the function ' | ||
+ | La routine « foncEffacer » efface simplement les deux variables mémoire, puis rafraîchit l' | ||
+ | def foncEffacer(self): | ||
+ | self.ValeurCourante = 0 | ||
+ | self.ValeurAncienne = 0 | ||
+ | self.Rafraichir() | ||
+ | |||
+ | Maintenant les fonctions. Nous avons déjà discuté de ce qui se passe avec la fonction « Dec ». Nous l' | ||
**The next set of steps are shown on the previous page (right hand box). | **The next set of steps are shown on the previous page (right hand box). | ||
Ligne 249: | Ligne 328: | ||
Finally we have our startup lines.** | Finally we have our startup lines.** | ||
+ | Les prochaines étapes sont indiquées sur la page précédente (encadré de droite). | ||
+ | La routine « Rafraichir » règle simplement la valeur de l' | ||
+ | |||
+ | def Rafraichir(self): | ||
+ | print(' | ||
+ | self.AffichageCourant.set(self.ValeurCourante) | ||
+ | |||
+ | Enfin, nous avons nos lignes de démarrage. | ||
**if __name__ == ' | **if __name__ == ' | ||
Ligne 261: | Ligne 348: | ||
Next month, we will continue looking at Tkinter and its wealth of widgets. In a future article, we'll look at a GUI designer for tkinter called PAGE. In the meantime, have fun playing. I think you'll enjoy Tkinter.** | Next month, we will continue looking at Tkinter and its wealth of widgets. In a future article, we'll look at a GUI designer for tkinter called PAGE. In the meantime, have fun playing. I think you'll enjoy Tkinter.** | ||
+ | if __name__ == ' | ||
+ | Demarrage() | ||
+ | |||
+ | Maintenant, vous pouvez exécuter le programme et l' | ||
+ | |||
+ | Comme toujours, le code de cet article peut être trouvé sur PasteBin. Les exemples 1, 2 et 3 sont ici : http:// | ||
+ | |||
+ | Le mois prochain, nous allons continuer à explorer Tkinter et la richesse de ses widgets. Dans un prochain article, nous verrons un concepteur d' | ||
+ | |||
+ | ====== CODE PAGE 7 ====== | ||
+ | remplacer l' | ||
+ | |||
+ | ====== CODE PAGE 8 ====== | ||
+ | class App: | ||
+ | def __init__(self, | ||
+ | cadre = Frame(principale) | ||
+ | self.lblTexte = Label(cadre, | ||
+ | self.btnQuitter = Button(cadre, | ||
+ | self.btnBonjour = Button(cadre, | ||
+ | cadre.grid(column = 0, row = 0) | ||
+ | self.lblTexte.grid(column = 0, row = 0, columnspan = 2) | ||
+ | self.btnBonjour.grid(column = 0, row = 1) | ||
+ | self.btnQuitter.grid(column = 1, row = 1) | ||
+ | |||
+ | |||
+ | ====== CODE PAGE 9 ====== | ||
+ | en haut à droite : remplacer CLEAR par EFFACER | ||
+ | |||
+ | juste en dessous : | ||
+ | |||
+ | from Tkinter import * | ||
+ | def Demarrage(): | ||
+ | global val, calc, racine | ||
+ | racine = Tk() | ||
+ | racine.title(' | ||
+ | racine.geometry(' | ||
+ | calc = Calculatrice(racine) | ||
+ | racine.mainloop() | ||
+ | |||
+ | en bas à gauche : | ||
+ | |||
+ | class Calculatrice(): | ||
+ | def __init__(self, | ||
+ | principale = Frame(racine) | ||
+ | self.ValeurCourante = 0 | ||
+ | self.ValeurAncienne = 0 | ||
+ | self.FonctionCourante = '' | ||
+ | self.AffichageCourant = StringVar() | ||
+ | self.AffichageCourant.set(' | ||
+ | self.PartieDecimale = False | ||
+ | self.CompteDecimales = 0 | ||
+ | self.DefinirWidgets(principale) | ||
+ | self.PlacerWidgets(principale) | ||
+ | |||
+ | ====== CODE PAGE 10 ====== | ||
+ | self.btn1 = Button(principale, | ||
+ | self.btn1.bind('< | ||
+ | self.btn2 = Button(principale, | ||
+ | self.btn2.bind('< | ||
+ | self.btn3 = Button(principale, | ||
+ | self.btn3.bind('< | ||
+ | self.btn4 = Button(principale, | ||
+ | self.btn4.bind('< | ||
+ | |||
+ | ====== CODE PAGE 11 ====== | ||
+ | self.btnDash = Button(principale, | ||
+ | self.btnDash.bind('< | ||
+ | self.btnDot = Button(principale, | ||
+ | self.btnDot.bind('< | ||
+ | |||
+ | Le bouton « btnDash » change le signe de la valeur affichée. 523 devient -523 et -523 devient 523. Le bouton btnDot saisit un point décimal. Ces exemples, ainsi que les suivants, utilisent la fonction foncBoutonFonction. | ||
+ | |||
+ | self.btnPlus = Button(principale, | ||
+ | self.btnPlus.bind('< | ||
+ | self.btnMinus = Button(principale, | ||
+ | self.btnMinus.bind('< | ||
+ | self.btnStar = Button(principale, | ||
+ | self.btnStar.bind('< | ||
+ | self.btnDiv = Button(principale, | ||
+ | self.btnDiv.bind('< | ||
+ | self.btnEqual = Button(principale, | ||
+ | self.btnEqual.bind('< | ||
+ | |||
+ | Voici les quatre boutons pour les fonctions mathématiques. | ||
+ | |||
+ | self.btnClear = Button(principale, | ||
+ | self.btnClear.bind('< | ||
+ | |||
+ | Enfin, voici le bouton Effacer. Il efface bien sûr les variables et l' | ||
+ | |||
+ | def PlacerWidgets(self, | ||
+ | principale.grid(column=0, | ||
+ | self.lblAffichage.grid(column=0, | ||
+ | self.btn1.grid(column = 0, row = 1) | ||
+ | self.btn2.grid(column = 1, row = 1) | ||
+ | self.btn3.grid(column = 2, row = 1) | ||
+ | self.btn4.grid(column = 0, row = 2) | ||
+ | self.btn5.grid(column = 1, row = 2) | ||
+ | self.btn6.grid(column = 2, row = 2) | ||
+ | self.btn7.grid(column = 0, row = 3) | ||
+ | self.btn8.grid(column = 1, row = 3) | ||
+ | self.btn9.grid(column = 2, row = 3) | ||
+ | self.btn0.grid(column = 1, row = 4) | ||
+ | |||
+ | ====== CODE PAGE 12 ====== | ||
+ | self.btnDash.grid(column = 0, row = 4) | ||
+ | self.btnDot.grid(column = 2, row = 4) | ||
+ | self.btnPlus.grid(column = 3,row = 1) | ||
+ | self.btnMinus.grid(column = 3, row = 2) | ||
+ | self.btnStar.grid(column = 3, row = 3) | ||
+ | self.btnDiv.grid(column=3, | ||
+ | self.btnEqual.grid(column=0, | ||
+ | self.btnClear.grid(column=0, | ||
+ | |||
+ | et en dessous : | ||
+ | |||
+ | def foncBoutonNumerique(self, | ||
+ | if self.PartieDecimale == True: | ||
+ | self.CompteDecimales += 1 | ||
+ | self.ValeurCourante = self.ValeurCourante + (val * (10**-self.CompteDecimales)) | ||
+ | else: | ||
+ | self.ValeurCourante = (self.ValeurCourante * 10) + val | ||
+ | self.Rafraichir()f.Rafraichir() | ||
+ | |||
+ | ====== CODE PAGE 13 ====== | ||
+ | def foncBoutonFonction(self, | ||
+ | if fonction == ' | ||
+ | self.PartieDecimale = True | ||
+ | else: | ||
+ | self.PartieDecimale = False | ||
+ | self.CompteDecimales = 0 | ||
+ | if fonction == ' | ||
+ | self.ValeurCourante *= -1 | ||
+ | self.Rafraichir() | ||
+ | |||
+ | la fonction SIGNE multiplie simplement la valeur courante par -1. | ||
+ | |||
+ | elif fonction == ' | ||
+ | self.ValeurAncienne = self.ValeurCourante | ||
+ | self.ValeurCourante = 0 | ||
+ | self.FonctionCourante = ' | ||
+ | |||
+ | La fonction Ajouter recopie « self.ValeurCourante » dans « self.ValeurAncienne », efface « self.ValeurCourante », et règle « self.FonctionCourante » à « Ajouter ». Les fonctions Soustraire, Multiplier et Diviser font la même chose avec les mots-clés appropriés. | ||
+ | |||
+ | elif fonction == ' | ||
+ | self.ValeurAncienne = self.ValeurCourante | ||
+ | self.ValeurCourante = 0 | ||
+ | self.FonctionCourante = ' | ||
+ | elif fonction == ' | ||
+ | self.ValeurAncienne = self.ValeurCourante | ||
+ | self.ValeurCourante = 0 | ||
+ | self.FonctionCourante = ' | ||
+ | elif fonction == ' | ||
+ | self.ValeurAncienne = self.ValeurCourante | ||
+ | self.ValeurCourante = 0 | ||
+ | self.FonctionCourante = ' | ||
+ | |||
+ | La fonction Egal est l' | ||
+ | |||
+ | elif fonction == ' | ||
+ | if self.FonctionCourante == ' | ||
+ | self.ValeurCourante += self.ValeurAncienne | ||
+ | elif self.FonctionCourante == ' | ||
+ | self.ValeurCourante = self.ValeurAncienne - self.ValeurCourante | ||
+ | elif self.FonctionCourante == ' | ||
+ | self.ValeurCourante *= self.ValeurAncienne | ||
+ | elif self.FonctionCourante == ' | ||
+ | self.ValeurCourante = self.ValeurAncienne / self.ValeurCourante | ||
+ | self.Rafraichir() | ||
+ | self.ValeurCourante = 0 | ||
+ | self.ValeurAncienne = 0 | ||
issue51/python_partie_25_pp._7-14.1313416296.txt.gz · Dernière modification : 2011/08/15 15:51 de fredphil91