• [^] # Re: on ne peut pas en l'état

    Posté par . En réponse au message Tkinter et scrollbar. Évalué à 2. Dernière modification le 19 février 2025 à 17:45.

    Un truc fait à l'arrache avec une frame et un simple canvas.
    Il faudrait quand même revoir ton script, et utiliser des frames pour grouper les widgets de ta fenêtre, là, c'est un peu le bazar.

    can_frame = tk.Frame(cadre, bd=2, highlightbackground='grey')
    can_frame.grid(padx=10, pady=10)
    line_height = 40
    can = tk.Canvas(
     can_frame,
     width=280,
     height=line_height * 10,
     highlightthickness=0,
     yscrollincrement=line_height,
    )
    can.grid(row=0, column=0)
    scroll = tk.Scrollbar(
     can_frame, width=20, orient=tk.VERTICAL, highlightthickness=0,
    )
    scroll.grid(row=0, column=1, sticky=tk.NSEW)
    can.config(yscrollcommand=scroll.set)
    scroll.config(command=can.yview)
    colors = 'lightGreen', 'lightBlue'
    radios_base_options = dict(
     fg='grey',
     highlightthickness=0,
    )
    for i in range(nb_joueurs):
     radios_options = dict(
     text=liste_joueurs[i],
     value=liste_joueurs[i],
     bg=colors[i % 2],
     )
     can.create_rectangle(
     0,
     i * line_height,
     can['height'],
     (i + 1) * line_height,
     fill=radios_options['bg'],
     width=0,
     )
     radio = tk.Radiobutton(
     can, variable=j1a, **radios_base_options, **radios_options
     )
     can.create_window(
     0,
     i * line_height + line_height / 2,
     window=radio,
     anchor=tk.W,
     )
     radio = tk.Radiobutton(
     can, variable=j1b, **radios_base_options, **radios_options
     )
     can.create_window(
     int(can['width']) / 2,
     i * line_height + line_height / 2,
     window=radio,
     anchor=tk.W,
     )
    can.configure(scrollregion=(0, 0, 0, i * line_height))

    Reste plus qu'à intégrer cela dans ton interface {o_o}

    Bonne continuation.