IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

Problème affichage scrollbar


Sujet :

Tkinter Python

  1. #1
    Candidat au Club
    Homme Profil pro
    Automaticien
    Inscrit en
    Novembre 2022
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Automaticien

    Informations forums :
    Inscription : Novembre 2022
    Messages : 2
    Points : 3
    Points
    3
    Par défaut Problème affichage scrollbar
    Dans le cadre d'un projet, je souhaite afficher les données d'une base de donnée.
    La communication avec la base de donnée est OK, par contre je n'arrive pas à afficher correctement les données.
    Ayant 25 données à afficher, la largeur du tableau est plus large que la largeur de la fenêtre. Je souhaite donc utiliser des scrollbars.
    Malheureusement je n'arrive pas à les afficher correctement.

    Voici le code :

    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
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
     
     
    # coding: utf-8
     
    from tkinter import *
    from tkinter import ttk
    import tkinter as tk
    from tkinter.ttk import *
     
    window = Tk()
     
    window.title('Meca Tooling')
     
     
    #definition des onglets
     
    style1 = ttk.Style()
    style1.configure("TNotebook.Tab", font = ('calibri', 16 ))
     
    tab_control = ttk.Notebook(window)
     
    tab1 = ttk.Frame(tab_control)
    tab2 = ttk.Frame(tab_control)
    tab3 = ttk.Frame(tab_control)
     
    tab_control.add(tab1, text='  Onglet 1  ')
    tab_control.add(tab2, text='  Onglet 2  ')
    tab_control.add(tab3, text='  Onglet 3  ')
     
    tab_control.pack(expand=1, fill='both')
     
     
    style2 = ttk.Style()
    style2.configure("BW3.TLabelframe.Label", font = ('calibri', 16 ))
     
    LabelFrame_BD = ttk.LabelFrame(tab1, text="Base de donnée", style="BW3.TLabelframe")
    LabelFrame_BD.pack(fill="both", padx=30, pady=10, expand="yes")
     
    tableau = ttk.Treeview(LabelFrame_BD, columns=( 'data_01',
                                                    'data_02',
                                                    'data_03',
                                                    'data_04',
                                                    'data_05',
                                                    'data_06',
                                                    'data_07',
                                                    'data_08',
                                                    'data_09',
                                                    'data_10',
                                                    'data_11',
                                                    'data_12',
                                                    'data_13',
                                                    'data_14',
                                                    'data_15',
                                                    'data_16',
                                                    'data_17',
                                                    'data_18',
                                                    'data_19',
                                                    'data_20',
                                                    'data_21',
                                                    'data_22',
                                                    'data_23',
                                                    'data_24',
                                                    'data_25',
                                                    'data_26',
                                                    'data_27',
                                                    'data_28',
                                                    'data_29',
                                                    'data_30'
                                                    ))
     
     
     
     
     
     
    tableau.heading('data_01', text='Data 01')
    tableau.heading('data_02', text='Data 02')
    tableau.heading('data_03', text='Data 03')
    tableau.heading('data_04', text='Data 04')
    tableau.heading('data_05', text='Data 05')
    tableau.heading('data_06', text='Data 06')
    tableau.heading('data_07', text='Data 07')
    tableau.heading('data_08', text='Data 08')
    tableau.heading('data_09', text='Data 09')
    tableau.heading('data_10', text='Data 10')
    tableau.heading('data_11', text='Data 11')
    tableau.heading('data_12', text='Data 12')
    tableau.heading('data_13', text='Data 13')
    tableau.heading('data_14', text='Data 14')
    tableau.heading('data_15', text='Data 15')
    tableau.heading('data_16', text='Data 16')
    tableau.heading('data_17', text='Data 17')
    tableau.heading('data_18', text='Data 18')
    tableau.heading('data_19', text='Data 19')
    tableau.heading('data_20', text='Data 20')
    tableau.heading('data_21', text='Data 21')
    tableau.heading('data_22', text='Data 22')
    tableau.heading('data_23', text='Data 23')
    tableau.heading('data_24', text='Data 24')
    tableau.heading('data_25', text='Data 25')
    tableau['show'] = 'headings'
     
     
    tableau.column('data_01', width=60, minwidth=60, anchor='c')
    tableau.column('data_02', width=60, minwidth=60, anchor='c')
    tableau.column('data_03', width=60, minwidth=100, anchor='c')
    tableau.column('data_04', width=60, minwidth=100, anchor='c')
    tableau.column('data_05', width=200, minwidth=100, anchor='c')
    tableau.column('data_06', width=100, minwidth=60, anchor='c')
    tableau.column('data_07', width=100, minwidth=150, anchor='c')
    tableau.column('data_08', width=100, minwidth=100, anchor='c')
    tableau.column('data_09', width=100, minwidth=100, anchor='c')
    tableau.column('data_10', width=100, minwidth=60, anchor='c')
    tableau.column('data_11', width=100, minwidth=60, anchor='c')
    tableau.column('data_12', width=100, minwidth=130, anchor='c')
    tableau.column('data_13', width=100, minwidth=100, anchor='c')
    tableau.column('data_14', width=100, minwidth=100, anchor='c')
    tableau.column('data_15', width=200, minwidth=220, anchor='c')
    tableau.column('data_16', width=100, minwidth=130, anchor='c')
    tableau.column('data_17', width=100, minwidth=110, anchor='c')
    tableau.column('data_18', width=100, minwidth=300, anchor='c')
    tableau.column('data_19', width=100, minwidth=120, anchor='c')
    tableau.column('data_20', width=100, minwidth=120, anchor='c')
    tableau.column('data_21', width=100, minwidth=120, anchor='c')
    tableau.column('data_22', width=100, minwidth=120, anchor='c')
    tableau.column('data_23', width=100, minwidth=100, anchor='c')
    tableau.column('data_24', width=100, minwidth=120, anchor='c')
    tableau.column('data_25', width=100, minwidth=120, anchor='c')
     
     
    #afficher_data_mesure(res)
     
     
    for i in tableau.get_children():
            tableau.delete(i)
    for i in range(100):
        tableau.insert('', 'end', iid=i, values=(   'data_01_' + str(i),
                                                    'data_02_' + str(i),
                                                    'data_03_' + str(i),
                                                    'data_04_' + str(i),
                                                    'data_05_' + str(i),
                                                    'data_06_' + str(i),
                                                    'data_07_' + str(i),
                                                    'data_08_' + str(i),
                                                    'data_09_' + str(i),
                                                    'data_10_' + str(i),
                                                    'data_11_' + str(i),
                                                    'data_12_' + str(i),
                                                    'data_13_' + str(i),
                                                    'data_14_' + str(i),
                                                    'data_15_' + str(i),
                                                    'data_16_' + str(i),
                                                    'data_17_' + str(i),
                                                    'data_18_' + str(i),
                                                    'data_19_' + str(i),
                                                    'data_20_' + str(i),
                                                    'data_21_' + str(i),
                                                    'data_22_' + str(i),
                                                    'data_23_' + str(i),
                                                    'data_24_' + str(i),
                                                    'data_25_' + str(i),
                                                    ))
     
     
     
    tableau.grid(column=0, row=0)
     
     
    # definition des scrollbar
     
    scrollbar_v = ttk.Scrollbar(LabelFrame_BD, orient=tk.VERTICAL, command=tableau.yview)
    scrollbar_v.grid(row=0, column=1, sticky='ns')
     
     
    scrollbar_h = ttk.Scrollbar(LabelFrame_BD, orient=tk.HORIZONTAL, command=tableau.xview)
    scrollbar_h.grid(row=1, column=0, sticky='we')
     
    window.attributes('-fullscreen', True)
     
     
    window.mainloop()
    Merci par avance pour votre aide

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 287
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 287
    Points : 36 776
    Points
    36 776
    Par défaut
    Salut,

    Citation Envoyé par boulou74 Voir le message
    Merci par avance pour votre aide
    Le widget dont il faut scroller le contenu est ttk.Treeview. On commence par chercher des exemples sur Internet avec les mots clefs "tkinter treeview scrollbar" et on essaie de comprendre comment ça fonctionne avant d'adapter cela à son code.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  3. #3
    Candidat au Club
    Homme Profil pro
    Automaticien
    Inscrit en
    Novembre 2022
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Automaticien

    Informations forums :
    Inscription : Novembre 2022
    Messages : 2
    Points : 3
    Points
    3
    Par défaut
    Finalement
    en utlisant la fonction place() j'ai réussit à m'en sortir

    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
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
     
    # coding: utf-8
     
    from tkinter import *
    from tkinter import ttk
    import tkinter as tk
    from tkinter.ttk import *
     
    window = Tk()
     
    window.title('Meca Tooling')
     
    #definition des onglets
     
    style1 = ttk.Style()
    style1.configure("TNotebook.Tab", font = ('calibri', 16 ))
     
    tab_control = ttk.Notebook(window)
     
    tab1 = ttk.Frame(tab_control)
    tab2 = ttk.Frame(tab_control)
    tab3 = ttk.Frame(tab_control)
     
    tab_control.add(tab1, text='  Onglet 1  ')
    tab_control.add(tab2, text='  Onglet 2  ')
    tab_control.add(tab3, text='  Onglet 3  ')
     
    tab_control.pack(expand=1, fill='both')
     
     
    style2 = ttk.Style()
    style2.configure("BW3.TLabelframe.Label", font = ('calibri', 16 ))
     
    LabelFrame_BD = ttk.LabelFrame(tab1, text="Base de donnée", style="BW3.TLabelframe")
    LabelFrame_BD.pack(fill="both", padx=30, pady=10, expand="yes")
     
     
    tableau = ttk.Treeview(LabelFrame_BD, columns=( 'data_01',
                                                    'data_02',
                                                    'data_03',
                                                    'data_04',
                                                    'data_05',
                                                    'data_06',
                                                    'data_07',
                                                    'data_08',
                                                    'data_09',
                                                    'data_10',
                                                    'data_11',
                                                    'data_12',
                                                    'data_13',
                                                    'data_14',
                                                    'data_15',
                                                    'data_16',
                                                    'data_17',
                                                    'data_18',
                                                    'data_19',
                                                    'data_20',
                                                    'data_21',
                                                    'data_22',
                                                    'data_23',
                                                    'data_24',
                                                    'data_25'
                                                    ))
     
     
     
     
     
     
    tableau.heading('data_01', text='Data 01')
    tableau.heading('data_02', text='Data 02')
    tableau.heading('data_03', text='Data 03')
    tableau.heading('data_04', text='Data 04')
    tableau.heading('data_05', text='Data 05')
    tableau.heading('data_06', text='Data 06')
    tableau.heading('data_07', text='Data 07')
    tableau.heading('data_08', text='Data 08')
    tableau.heading('data_09', text='Data 09')
    tableau.heading('data_10', text='Data 10')
    tableau.heading('data_11', text='Data 11')
    tableau.heading('data_12', text='Data 12')
    tableau.heading('data_13', text='Data 13')
    tableau.heading('data_14', text='Data 14')
    tableau.heading('data_15', text='Data 15')
    tableau.heading('data_16', text='Data 16')
    tableau.heading('data_17', text='Data 17')
    tableau.heading('data_18', text='Data 18')
    tableau.heading('data_19', text='Data 19')
    tableau.heading('data_20', text='Data 20')
    tableau.heading('data_21', text='Data 21')
    tableau.heading('data_22', text='Data 22')
    tableau.heading('data_23', text='Data 23')
    tableau.heading('data_24', text='Data 24')
    tableau.heading('data_25', text='Data 25')
    tableau['show'] = 'headings'
     
     
    tableau.column('data_01', width=60, minwidth=60, anchor='c')
    tableau.column('data_02', width=60, minwidth=60, anchor='c')
    tableau.column('data_03', width=60, minwidth=100, anchor='c')
    tableau.column('data_04', width=60, minwidth=100, anchor='c')
    tableau.column('data_05', width=200, minwidth=100, anchor='c')
    tableau.column('data_06', width=100, minwidth=60, anchor='c')
    tableau.column('data_07', width=100, minwidth=150, anchor='c')
    tableau.column('data_08', width=100, minwidth=100, anchor='c')
    tableau.column('data_09', width=100, minwidth=100, anchor='c')
    tableau.column('data_10', width=100, minwidth=60, anchor='c')
    tableau.column('data_11', width=100, minwidth=60, anchor='c')
    tableau.column('data_12', width=100, minwidth=130, anchor='c')
    tableau.column('data_13', width=100, minwidth=100, anchor='c')
    tableau.column('data_14', width=100, minwidth=100, anchor='c')
    tableau.column('data_15', width=200, minwidth=220, anchor='c')
    tableau.column('data_16', width=100, minwidth=130, anchor='c')
    tableau.column('data_17', width=100, minwidth=110, anchor='c')
    tableau.column('data_18', width=100, minwidth=300, anchor='c')
    tableau.column('data_19', width=100, minwidth=120, anchor='c')
    tableau.column('data_20', width=100, minwidth=120, anchor='c')
    tableau.column('data_21', width=100, minwidth=120, anchor='c')
    tableau.column('data_22', width=100, minwidth=120, anchor='c')
    tableau.column('data_23', width=100, minwidth=100, anchor='c')
    tableau.column('data_24', width=100, minwidth=120, anchor='c')
    tableau.column('data_25', width=100, minwidth=120, anchor='c')
     
     
    #afficher_data_mesure(res)
     
     
    for i in tableau.get_children():
            tableau.delete(i)
    for i in range(100):
        tableau.insert('', 'end', iid=i, values=(   'data_01_' + str(i),
                                                    'data_02_' + str(i),
                                                    'data_03_' + str(i),
                                                    'data_04_' + str(i),
                                                    'data_05_' + str(i),
                                                    'data_06_' + str(i),
                                                    'data_07_' + str(i),
                                                    'data_08_' + str(i),
                                                    'data_09_' + str(i),
                                                    'data_10_' + str(i),
                                                    'data_11_' + str(i),
                                                    'data_12_' + str(i),
                                                    'data_13_' + str(i),
                                                    'data_14_' + str(i),
                                                    'data_15_' + str(i),
                                                    'data_16_' + str(i),
                                                    'data_17_' + str(i),
                                                    'data_18_' + str(i),
                                                    'data_19_' + str(i),
                                                    'data_20_' + str(i),
                                                    'data_21_' + str(i),
                                                    'data_22_' + str(i),
                                                    'data_23_' + str(i),
                                                    'data_24_' + str(i),
                                                    'data_25_' + str(i),
                                                    ))
     
     
    #calcul des différentes positions
    screen_width = window.winfo_screenwidth()
    screen_height = window.winfo_screenheight()
    taille_srollbar = 22
     
    relx_tab = 10 / (screen_width - 60)
    rely_tab = 10 / (screen_height -20)
    width_tab = screen_width - taille_srollbar - 60 - 20
    height_tab = screen_height - taille_srollbar - 20 - 80
    relx_scroll_bar_v = (10 + width_tab) / (screen_width - 65)
    rely_scroll_bar_h = (40 + height_tab) / (screen_height - 55)
     
    tableau.place(relx=relx_tab, rely=rely_tab, width=width_tab, height=height_tab)
     
    # definition des scrollbar
     
    scrollbar_v = ttk.Scrollbar(LabelFrame_BD, orient=tk.VERTICAL, command=tableau.yview)
    scrollbar_v.place(relx=relx_scroll_bar_v, rely=rely_tab, width=taille_srollbar, height=height_tab )
    tableau.configure(yscrollcommand = scrollbar_v.set)
     
    scrollbar_h = ttk.Scrollbar(LabelFrame_BD, orient=tk.HORIZONTAL, command=tableau.xview)
    scrollbar_h.place(relx=relx_tab, rely=rely_scroll_bar_h, width=width_tab , height=taille_srollbar)
    tableau.configure(xscrollcommand = scrollbar_h.set)
     
    window.attributes('-fullscreen', True)
     
     
    window.mainloop()

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème d'affichage scrollbar
    Par jaky33 dans le forum Tkinter
    Réponses: 22
    Dernier message: 01/03/2018, 15h01
  2. problème affichage boutons scrollbar
    Par Melodie dans le forum Composants VCL
    Réponses: 3
    Dernier message: 30/09/2009, 21h13
  3. Problème affichage primitive
    Par goutbouyo dans le forum DirectX
    Réponses: 4
    Dernier message: 29/12/2004, 18h25
  4. [Plugin][VE] Problème affichage
    Par sebb84 dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 05/07/2004, 14h50
  5. [DOS] Problème affichage de DOS dans un Memo
    Par Pedro dans le forum API, COM et SDKs
    Réponses: 9
    Dernier message: 25/06/2004, 13h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo