Last active
October 1, 2018 20:05
-
-
Save Franck1333/08e0d6a633779d9f4d798babb4df4bfb to your computer and use it in GitHub Desktop.
Get a Scrollbar on Tkinter example found.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # CANVAS | |
| #AIDES: http://apprendre-python.com/page-tkinter-interface-graphique-python-tutoriel | |
| try : | |
| from Tkinter import * #Python Version 2 | |
| pass | |
| except: | |
| from tkinter import * #Python Version 3 | |
| fenetre = Tk() | |
| # canvas | |
| scrollbar = Scrollbar(fenetre) #Création/Déclaration d'une variable Scrollbar(dans la fenêtre) | |
| scrollbar.pack(side=RIGHT, fill=Y) #Placement de la Scollbar dans la fenêtre | |
| canvas = Canvas(fenetre, width=150, height=120, background='yellow',yscrollcommand=scrollbar.set) | |
| ligne1 = canvas.create_line(75, 0, 75, 120) | |
| ligne2 = canvas.create_line(0, 60, 150, 60) | |
| txt = canvas.create_text(75, 60, text="Cible", font="Arial 16 italic", fill="blue") | |
| canvas.pack() | |
| scrollbar.config(command=canvas.yview) #Configuration de la Scrollbar par rapport a son objet et de son orientation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Aides: http://effbot.org/tkinterbook/listbox.htm | |
| #Aides: https://www.tutorialspoint.com/python/tk_listbox.htm | |
| try : | |
| from Tkinter import * #Python Version 2 | |
| pass | |
| except: | |
| from tkinter import * #Python Version 3 | |
| master = Tk() | |
| scrollbar = Scrollbar(master) | |
| scrollbar.pack(side=RIGHT, fill=Y) | |
| listbox = Listbox(master) | |
| listbox.pack() | |
| #listbox.insert(END, "a list entry") | |
| for item in ["one", "two", "three", "four"]: | |
| listbox.insert(END, item) | |
| # attach listbox to scrollbar | |
| listbox.config(yscrollcommand=scrollbar.set) | |
| scrollbar.config(command=listbox.yview) | |
| mainloop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Aides: http://effbot.org/tkinterbook/scrollbar.htm | |
| try : | |
| from Tkinter import * #Python Version 2 | |
| pass | |
| except: | |
| from tkinter import * #Python Version 3 | |
| def version1(): | |
| master = Tk() #Création de la Fenêtre MASTER | |
| scrollbar = Scrollbar(master) #Création/Déclaration d'une variable Scrollbar(dans la fenêtre MASTER) | |
| scrollbar.pack(side=RIGHT, fill=Y) #Placement de la Scollbar dans la fenêtre | |
| listbox = Listbox(master, yscrollcommand=scrollbar.set) #Liaison de la ScrollBar à son objet relié à la fenêtre MASTER | |
| for i in range(1000): | |
| listbox.insert(END, str(i)) | |
| listbox.pack(side=LEFT, fill=BOTH) | |
| scrollbar.config(command=listbox.yview) #Configuration de la Scrollbar par rapport a son objet et de son orientation | |
| mainloop() | |
| def version2(): | |
| root = Tk() | |
| scrollbar = Scrollbar(root) | |
| scrollbar.pack(side=RIGHT, fill=Y) | |
| listbox = Listbox(root) | |
| listbox.pack() | |
| for i in range(100): | |
| listbox.insert(END, i) | |
| # attach listbox to scrollbar | |
| listbox.config(yscrollcommand=scrollbar.set) | |
| scrollbar.config(command=listbox.yview) | |
| mainloop() | |
| if __name__ == "__main__": | |
| #version1() | |
| version2() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # TEXT WIDGET | |
| #AIDES: http://apprendre-python.com/page-tkinter-interface-graphique-python-tutoriel | |
| #AIDES: http://www.jchr.be/python/tkinter.htm#scrollbar | |
| try : | |
| from Tkinter import * #Python Version 2 | |
| pass | |
| except: | |
| from tkinter import * #Python Version 3 | |
| fenetre = Tk() | |
| scrollbar = Scrollbar(fenetre) #Création/Déclaration d'une variable Scrollbar(dans la fenêtre MASTER) | |
| scrollbar.pack(side=RIGHT, fill=Y) #Placement de la Scollbar dans la fenêtre | |
| texte0=Text(fenetre, yscrollcommand=scrollbar.set) | |
| texte0.insert(END, "bla bla bla "*3) | |
| texte0.insert(END, "\n"+"BOUHHHHHHHHHH"*2 + "\n") | |
| texte0.pack(side=LEFT, fill=BOTH) | |
| scrollbar.config(command=texte0.yview) | |
| fenetre.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment