|
|
@ -1,5 +1,6 @@ |
|
|
import tkinter as tk |
|
|
import tkinter as tk |
|
|
from tkinter.constants import * |
|
|
from tkinter.constants import * |
|
|
|
|
|
from tkinter import font |
|
|
|
|
|
|
|
|
class Fenetre(tk.Tk): |
|
|
class Fenetre(tk.Tk): |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
@ -7,12 +8,30 @@ class Fenetre(tk.Tk): |
|
|
self.title("Calculatrice") |
|
|
self.title("Calculatrice") |
|
|
self.geometry("400x600") |
|
|
self.geometry("400x600") |
|
|
self.configure(bg='pink') |
|
|
self.configure(bg='pink') |
|
|
tk.Canvas(self, width=350, height=175, bg='ivory').pack(side=TOP, padx=5, pady=25) |
|
|
self.font= font.Font(family="Arial", size=30, weight="bold" ) |
|
|
self.frame = tk.Frame(self, bg='pink') |
|
|
#configuration des lignes et des colonnes afin de bien placer les boutons |
|
|
self.entree = tk.Entry(self.frame, width=30) |
|
|
self.grid_rowconfigure(0, weight = 4) |
|
|
self.entree.pack(side=TOP, anchor='n', padx = 5, pady = 100) |
|
|
for i in range(1, 5): |
|
|
self.bouton = tk.Button(self.frame, text="Calculer", bg='white').pack(anchor = 's', padx = 100, pady = 10) |
|
|
self.grid_rowconfigure(i, weight = 1) |
|
|
self.frame.pack(padx = 5, pady =40) |
|
|
for j in range(4): |
|
|
|
|
|
self.grid_columnconfigure(j, weight = 1) |
|
|
|
|
|
#ajout de l'ecran et des boutons de la calculatrice |
|
|
|
|
|
self.texte = "" |
|
|
|
|
|
self.ecran = tk.Label(self, text=self.texte,font=("Arial", 60), bg="#EDFAF0") |
|
|
|
|
|
self.ecran.grid(row = 0, column=0, columnspan=4, sticky="nsew") |
|
|
|
|
|
touches = ("7", "8", "9", "+", "4", "5", "6", "-", "1", "2", "3", "*", "0", ",", "=", "/") |
|
|
|
|
|
ligne = 1 |
|
|
|
|
|
colonne = 0 |
|
|
|
|
|
for touche in touches: |
|
|
|
|
|
tk.Button(self, text=touche,command=lambda t=touche:self.calculer(t), font = self.font).grid(row=ligne, column = colonne) |
|
|
|
|
|
colonne += 1 |
|
|
|
|
|
if colonne == 4: |
|
|
|
|
|
colonne = 0 |
|
|
|
|
|
ligne += 1 |
|
|
|
|
|
|
|
|
|
|
|
def calculer(self, element): |
|
|
|
|
|
#if element == "=": |
|
|
|
|
|
self.texte = self.texte + element |
|
|
|
|
|
self.ecran.config(text=self.texte) |
|
|
window = Fenetre() |
|
|
window = Fenetre() |
|
|
window.mainloop() |
|
|
window.mainloop() |