You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.4 KiB
37 lines
1.4 KiB
import tkinter as tk
|
|
from tkinter.constants import *
|
|
from tkinter import font
|
|
|
|
class Fenetre(tk.Tk):
|
|
def __init__(self):
|
|
tk.Tk.__init__(self)
|
|
self.title("Calculatrice")
|
|
self.geometry("400x600")
|
|
self.configure(bg='pink')
|
|
self.font= font.Font(family="Arial", size=30, weight="bold" )
|
|
#configuration des lignes et des colonnes afin de bien placer les boutons
|
|
self.grid_rowconfigure(0, weight = 4)
|
|
for i in range(1, 5):
|
|
self.grid_rowconfigure(i, weight = 1)
|
|
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.mainloop()
|