Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Autohiding Scrollbars using Python-tkinter
Next article icon
Tkinter is a Python binding to the Tk GUI(Graphical User Interface) Toolkit. It is a thin-object oriented layer on top of Tcl/Tk. When combined with Python, it helps create fast and efficient GUI applications.Note: For more information refer,Python GUI-tkinter

Steps to Create a double scrollbar frame in Tkinter

1) Firstly, the module Tkinter will be imported as:
import tkinter as tk
So,tkinter is abbreviated here astk so as to make the code look cleaner and efficient.Now, a window will be created to display:Python3
importtkinterastkwindow=tk.Tk()window.geometry("250x200")
Output:Functions to understand:
  • geometry(): This method is used to set the dimensions of the Tkinter window as well as it is used to set the position of the main window on the user’s desktop.
2) The next code is to assign to the scrollbars for horizontal and vertical.Python3
SVBar=tk.Scrollbar(window)SVBar.pack(side=tk.RIGHT,fill="y")SHBar=tk.Scrollbar(window,orient=tk.HORIZONTAL)SHBar.pack(side=tk.BOTTOM,fill="x")
Output:Functions to understand:
  • Scrollbar() = It is the scrollbar that is allotted to the sides of the window.
  • pack() method: It organizes the widgets in blocks before placing in the parent widget.
3) Now, make a text box for the window:Python3
TBox=tk.Text(window,height=500,width=500,yscrollcommand=SVBar.set,xscrollcommand=SHBar.set,wrap="none")TBox=tk.Text(window,height=500,width=500,yscrollcommand=SVBar.set,xscrollcommand=SHBar.set,wrap="none")TBox.pack(expand=0,fill=tk.BOTH)
Functions to understand:
  • Text() = It is a textbox widget of a standard Tkinter widget used to display the text.
  • pack() = It is a geometry manager for organizing the widgets in blocks before placing them in the parent widget. Options like fill, expand and side are used in the function.
SHBar.config(command = TBox.xview)SVBar.config(command = TBox.yview)
Here, within the arguments of the functionconfig(), the scrollbars are assigned at their specific x-axis and y-axis and are able to function.Now, insert some amount of text to display:
Num_Vertical = ("\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ")Num_Horizontal = ("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z")
To insert the text in the window for the display, the following code is done:Python3
TBox.insert(tk.END,Num_Horizontal)TBox.insert(tk.END,Num_Vertical)
Complete Code:Python3
importtkinterastkNum_Vertical=("\nA\nB\nC\nD\nE\nF\nG\n\H\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\n\U\nV\nW\nX\nY\nZ")Num_Horizontal=("A  B  C  D  E  F  G  H\I  J  K  L  M  N  O  P  Q  R  S  T  U  V\W  X  Y  Z")window=tk.Tk()window.geometry("250x200")SVBar=tk.Scrollbar(window)SVBar.pack(side=tk.RIGHT,fill="y")SHBar=tk.Scrollbar(window,orient=tk.HORIZONTAL)SHBar.pack(side=tk.BOTTOM,fill="x")TBox=tk.Text(window,height=500,width=500,yscrollcommand=SVBar.set,xscrollcommand=SHBar.set,wrap="none")TBox=tk.Text(window,height=500,width=500,yscrollcommand=SVBar.set,xscrollcommand=SHBar.set,wrap="none")TBox.pack(expand=0,fill=tk.BOTH)TBox.insert(tk.END,Num_Horizontal)TBox.insert(tk.END,Num_Vertical)SHBar.config(command=TBox.xview)SVBar.config(command=TBox.yview)window.mainloop()
Output:

Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp