logo
down
shadow

How do I set the width of a Tkinter.Text widget scrollbar?


How do I set the width of a Tkinter.Text widget scrollbar?

By : user2950771
Date : November 17 2020, 11:58 AM
like below fixes the issue I'm trying to create a Tkinter Text widget with a Scrollbar. This is working all fine, except I want the Scrollbar to have a width of 12 pixels, instead of the default value of 16 pixels. On the documentation online, it states that width is indeed an option you can set. So what am I doing wrong? Below is the code I have tried using. , Your code works, see the screenshots:
width=5:
code :


Share : facebook icon twitter icon
python tkinter scrollbar and text widget issues

python tkinter scrollbar and text widget issues


By : user3386821
Date : March 29 2020, 07:55 AM
hope this fix your issue The trick is to use Frames and add the Scrollbars to the Frames instead of to Root.
code :
from Tkinter import *

root = Tk()

left = Frame(root)
right = Frame(root)

t_start = Text(left, width=20)
t_start.pack(side=LEFT, fill=Y)
s_start = Scrollbar(left)
s_start.pack(side=RIGHT, fill=Y)
s_start.config(command=t_start.yview)
t_start.config(yscrollcommand=s_start.set)

t_end = Text(right, width=20)
t_end.pack(side=LEFT, fill=Y)
s_end = Scrollbar(right)
s_end.pack(side=RIGHT, fill=Y)
s_end.config(command=t_end.yview)
t_end.config(yscrollcommand=s_end.set)

left.pack(side=LEFT, fill=Y)
right.pack(side=RIGHT, fill=Y)

root.geometry("500x200")
root.mainloop()
Tkinter - Text widget shrinks when Scrollbar is added

Tkinter - Text widget shrinks when Scrollbar is added


By : Ted Cox
Date : March 29 2020, 07:55 AM
it fixes the issue You don't want to use a text widget as the master for a scrollbar. Like any other widget, if you pack or grid the scrollbar in the text widget, the text widget will shrink or expand to fit the scrollbar. That is the crux of your problem.
Instead, create a separate frame (which you're already doing), and use that frame as the parent for both the text widget and the scrollbars. If you want the appearance that the scrollbars are inside, set the borderwidth of the text widget to zero, and then give the containing frame a small border.
code :
import Tkinter as tk

class Q_and_A(tk.Frame):
    def __init__(self, master):
        tk.Frame.__init__(self, master, borderwidth=1, relief="sunken")
        self.label = tk.Label(self)
        self.results_txtbx = tk.Text(self, width=20, height=4, wrap="none",
                                     borderwidth=0, highlightthickness=0)
        self.results_scrbr = tk.Scrollbar(self, orient="vertical", 
                                          command=self.results_txtbx.yview)
        self.results_txtbx.configure(yscrollcommand=self.results_scrbr.set)

        self.label.grid(row=1, columnspan=2)
        self.results_scrbr.grid(row=0, column=1, sticky="ns")
        self.results_txtbx.grid(row=0, column=0, sticky="nsew")
        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)

root = tk.Tk()
root.wm_title("Question And Answer")

app = Q_and_A(root)
app.pack(side="top", fill="both", expand=True)
root.mainloop()
Scrollbar to scroll Text widget, using Grid layout, in Tkinter

Scrollbar to scroll Text widget, using Grid layout, in Tkinter


By : sbara
Date : March 29 2020, 07:55 AM
Does that help Add North and South to the sticky option of the Scrollbar grid call, so the Scrollbar is stretched in vertical direction.
code :
self.scrollbar.grid(column=6, row=5, rowspan=2,  sticky=N+S+W)
Scrollbar in Tkinter inside Text widget

Scrollbar in Tkinter inside Text widget


By : ashish bhardwaj
Date : March 29 2020, 07:55 AM
may help you . While I rarely recommend place, it is quite powerful when you take advantage of the configuration options. For example, you can use in_ to specify a widget that this widget is to be placed relative to. You can use relx to specify a relative x coordinate, and you can use relheight to specify a height.
In your case you can try something like this:
code :
vscroll.place(in_=txtOutput, relx=1.0, relheight=1.0, bordermode="outside")
txtFrame = Frame(frame, borderwidth=1, relief="sunken")
txtOutput = Text(txtFrame, wrap = NONE, height = 17, width = 70, borderwidth=0)
vscroll = Scrollbar(txtFrame, orient=VERTICAL, command=txtOutput.yview)
txtOutput['yscroll'] = vscroll.set

vscroll.pack(side="right", fill="y")
txtOutput.pack(side="left", fill="both", expand=True)

txtFrame.place(x=10, y=75)
Python Tkinter ttk Scrollbar on Text widget not scaling

Python Tkinter ttk Scrollbar on Text widget not scaling


By : lucasmarcos
Date : March 29 2020, 07:55 AM
it helps some times Boy, this was a difficult one. Turns out the scrollbar reacts weird when your text consists of just one very long line. Try inserting a text with linebreaks:
code :
t.insert(INSERT, "Begin " + "This is a test \n" * 800 + " END")
Related Posts Related Posts :
  • pretty printing numpy ndarrays using unicode characters
  • Frequent pattern mining in Python
  • How can I make a set of functions that can be used synchronously as well as asynchronously?
  • Convert one dice roll to two dice roll
  • count occourrence in a list
  • Writing an If condition to filter out the first word
  • to read file and compare column in python
  • Install python-numpy in the Virtualenv environment
  • `.select_by_visible_text()` is failed to select element?
  • Unable to send data multiple requests in a single connection — socket error
  • Pandas HDFStore unload dataframe from memory
  • Creating a custom admin view
  • How do you get the user role of the currently logged in user in Ckan?
  • Speed up Numpy Meshgrid Command
  • Python error - name lengths
  • appending text to a global variable
  • Python Mistake - Number of letters in name
  • Searching for a sequence in a text
  • Testing logging output with pytest
  • How do I change my default working directory for Python (Anaconda) on VSCode?
  • .lower() for x in list, not working, but works in another scenario
  • Program gives error "List indices must not be string"
  • pyqt: Memory Usage
  • Confused about classes in Learn Python the Hard Way ex43?
  • Extracting unrecognized information from many CSV files
  • How do I connect to Postgresql server from Python?
  • Append rows to a pandas DataFrame without making a new copy
  • Scrapy: Importing a package from the project that's not in the same directory
  • launching Excel application using Python to view the CSV file , but CSV file is opening in read mode and cant view the d
  • Making a list in user-defined functions
  • Pyserial microcontroller to host communication
  • Plotting a line in between subplots
  • function not returning value. Error "NameError: name 'urlss' is not defined"
  • How to perform cartesian product with Tensorflow?
  • Multiple independent random number streams from single seed
  • I Need a simple and short python3 code that count secounds in a background process
  • No module named constants
  • from django 1.4 to django 1.5- argument 'verify_exists' what s replacement?
  • Slash replacement inside a raw string
  • Reordering columns/rows of a pivot_table?
  • MySQLdb.cursors.Cursor.execute does not work
  • Python module being reimported when imported at different places
  • Is the Session object from Python's Requests library thread safe?
  • Python Regex: Finding First and Last Names
  • Order by selection in List view of OpenERP 7.0
  • Reading input values in ipython notebook
  • List of dictionaries - how to read a specific value in a dictionary
  • writing os.system output to file
  • Create dictionary from points list and multiple attribute lists
  • How to write a table line by line with for loop
  • Map projection and forced interpolation
  • Django FBV's "render_to_response" equivalent in Class-Based-View?
  • Paramiko raises "SFTPError: Garbage packet received"
  • python pandas operations on columns
  • python list appending is not working
  • Speeding up matplotlib scatter plots
  • For each element of the list find closest date from a different list
  • How to prepend new rows at the beginning of an existing csv file?
  • how to make database robust to process kills with sqlite postgress and sqlalchemy?
  • finding a set of ranges that a number fall in
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org