J'ai continué mon projet d'interface pour calculatrice. Voila pour le moment ce que j'ai.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# coding: utf-8
from tkinter import *
import tkinter as tk
from tkinter.messagebox import *
 
main = Tk()
main.title('1er version')
main['bg'] = '#abc'
nomfichier = 'CasioMaker.txt'
main.resizable(width=False,height=False)
 
#A propos de l'affichage
taille_x = 127
taille_y = 63
disp_x = 10
disp_y = 10
 
def a(): 
    #Ecriture dans le fichier
    fichier = open(nomfichier, 'w')
    fichier.write('\'Made by Tituya\n')
    fichier.write('Cls\n')
    fichier.write('ViewWindow 1,127,1,1,63,1\n')
    fichier.write('AxesOff\n')
    fichier.close()
 
def c(): #Reset de la grille
    for ligne1 in range(taille_y):
        for colonne1 in range(taille_x):
            button = tk.Button(frame_b, borderwidth=1, background='white', width=2, height=1)
            button['command'] = lambda button=button: button.configure(background = 'black')
            button.grid(row=ligne1, column=colonne1)
 
def b(): #Lors du quit
    if askyesno('Titre 1', 'Etes vous sur ? Toutes progression sera effacée'):
        main.destroy()
    else:
        pass
 
#Image CasioMaker
photo = PhotoImage(file="ma_photo.png")
frametxt = Frame(main, relief=FLAT)
frametxt.pack(side=TOP)
cantxt = Canvas(frametxt, width=300, height=25, bg=main['bg'], relief=FLAT)
cantxt.create_image(150, 12, anchor=CENTER, image=photo)
cantxt.pack(side=TOP)
 
frame = Frame(main)
frame.pack(padx=10, pady=100)
can = Canvas(frame, background='yellow')
can.grid(row=0, column=0)
 
#Barre vertical
vsbar = Scrollbar(frame, orient=VERTICAL, command=can.yview)
vsbar.grid(row=0, column=1, sticky=NS)
can.configure(yscrollcommand=vsbar.set)
#Barre horizontal
hsbar = Scrollbar(frame, orient=HORIZONTAL, command=can.xview)
hsbar.grid(row=1, column=0, sticky=EW)
can.configure(xscrollcommand=hsbar.set)
 
frame_b = Frame(can)
 
#Generation des boutons
for ligne in range(taille_y):
    for colonne in range(taille_x):
        button = tk.Button(frame_b, borderwidth=1, background='white', width=2, height=1)
        button['command'] = lambda button=button: button.configure(background = 'black')
        button.grid(row=ligne, column=colonne)
 
can.create_window((0,0), window=frame_b, anchor=NW)
frame_b.update_idletasks()
bbox = can.bbox(ALL)
 
w, h = bbox[2]-bbox[1], bbox[3]-bbox[1]
dw, dh = int((w/taille_x) * disp_x), int((h/taille_y) * disp_y)
can.configure(scrollregion=bbox, width=dw, height=dh)
 
#Menu du haut
menu = Menu(main)
sousmenu = Menu(menu, tearoff=0)
menu.add_cascade(label="Menu", menu=sousmenu)
sousmenu.add_command(label="Creer le fichier texte", command=a)
sousmenu.add_command(label="Quitter", command=b)
menu.add_command(label="Effacer", command=c)
main.config(menu = menu)
 
#Faux ecran de calc
bottom_frame = Frame(main)
bottom_frame.pack( side = BOTTOM )
 
canvas = Canvas(bottom_frame, width=127, height=63, background='#7E9658')
canvas.pack( side = BOTTOM)
 
main.mainloop()
Ce qui donne ceci à l'ecran.
Nom : Capture.PNG
Affichages : 1545
Taille : 33,1 Ko

Le rendu est pas trop mal je trouve.

Seulement, malgré cet interface, le code ne fonctionne pas du tout ! Mon but est de détecter la couleur d'un bouton noir pour ensuite récupérer sa position (1,1 pour en bas a gauche et 127,63 pour en haut a droite).

Pour ceci, j'ai besoin de savoir quel bouton est appuyé.

Aussi, comme vous l'aurez remarqué, j'ai un espace vert en dessous de ma fenetre. Cet espace, je l'ai créer pour faire une sorte de visualisation de l'ensemble. Donc il faudrait que lors de l'ajout d'un bouton noir, ce canvas localise et replace au pixel notre "dessin".

Je ne sais absolument pas si mon projet est possible ou si il est réalisable avec de grandes difficultés. Mais peu importe, après tout, c'est surtout pour apprendre que je fais ceci

Dans l'attente de vos réponses

Cordialement.