Re re problème de scrollbar

Fermé
Pr.Witherfire - 11 mars 2023 à 19:46
Phil_1857 Messages postés 1872 Date d'inscription lundi 23 mars 2020 Statut Membre Dernière intervention 28 février 2024 - 13 mars 2023 à 11:36

Bonjour. J'aimerais faire fonctionner un scrollbar dans ce cas là:

from tkinter import *

F = Tk()
Color1 = "white"
Color2 = "black"
Police = "Impact"
F.title("Menu")
F.geometry("1600x900+-8+0")

Sb = Scrollbar(F, orient='vertical')
Sb.pack(side=RIGHT, fill='y')

C = Canvas(F, bg=Color2, width=1525, height=6000, yscrollcommand=Sb.set, bd=0)

Frame = Frame(F, bg=Color1, width=1525, height=6000)


for i in range(5):

    Nom = i
    globals()["Frame"+str(Nom)]= Canvas(Frame, bg=Color2, width=400, height=285, bd=0)

    if i == 0:
        x=0
        y=0
    else:

        x=x+250
        y=y+150

    globals()["Frame" + str(Nom)].place(x=x, y=y)

Frame.place(x=0, y=270)
C.place(x=0, y=270)

Sb.config(command=C.yview)

F.mainloop()

mais je n'y arrive pas pouvez vous m'aider merci au revoir

3 réponses

yg_be Messages postés 22867 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 12 juin 2024 1 474
12 mars 2023 à 23:48
0
yg_be Messages postés 22867 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 12 juin 2024 1 474
13 mars 2023 à 11:31

ton if dans la boucle for est très barbare.

Au lieu de

for i in range(5):
    if i == 0:
        x=0
    else:
        x=x+250
    print(x)

Il est plus clair et plus efficace d'écrire

x=0
for i in range(5):
    print(x)
    x=x+250

Ou même

for i in range(5):
    x=i*250
    print(x)
0
Phil_1857 Messages postés 1872 Date d'inscription lundi 23 mars 2020 Statut Membre Dernière intervention 28 février 2024 168
Modifié le 13 mars 2023 à 11:37

Bonjour,

Par contre je vois que tu continues à utiliser globals() malgré les remarques précédentes

Il suffit de faire ça:

frame = Frame(F, bg=Color1, width=1525, height=6000)
for i in range(5):
    frame[i]= Canvas(Frame, bg=Color2, width=400, height=285, bd=0)

Et des noms de widgets qui sont des mots réservés de Python:

Frame = Frame(.....) !

0