Python Forum
[Tkinter] Same Scrollbar for two text area
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Same Scrollbar for two text area
#1
Hi,

I have two text area and two separate scroll bar assigned for them. i need a single scrollbar which can scroll both area ? is that possible?? attaching my code below and current UI.


root = tk.Tk()
    textContainer = tk.Frame(root, borderwidth=1, relief="sunken")
    root.title("Comparison")
    #First Text Window
    text = tk.Text(textContainer, width=24, height=13, wrap="none", borderwidth=0)
    textVsb = tk.Scrollbar(textContainer, orient="vertical", command=text.yview)
    textHsb = tk.Scrollbar(textContainer, orient="horizontal", command=text.xview)
    text.configure(yscrollcommand=textVsb.set, xscrollcommand=textHsb.set)
    
    text.insert(tkinter.INSERT,Source_Value)
    text.grid(row=0, column=0, sticky="nsew")
    textVsb.grid(row=0, column=1, sticky="ns")
    textHsb.grid(row=1, column=0, sticky="ew")
    
    #Second Text Window
    text1 = tk.Text(textContainer, width=24, height=13, wrap="none", borderwidth=0)
    text1Vsb = tk.Scrollbar(textContainer, orient="vertical", command=text1.yview)
    text1Hsb = tk.Scrollbar(textContainer, orient="horizontal", command=text1.xview)
    text1.configure(yscrollcommand=text1Vsb.set, xscrollcommand=text1Hsb.set)
    
        
    text1.insert(tkinter.INSERT,Target_Value)
    text1.grid(row=0, column=2, sticky="nsew")
    text1Vsb.grid(row=0, column=3, sticky="ns")
    text1Hsb.grid(row=1, column=2, sticky="ew")
    
    
    textContainer.grid_rowconfigure(0, weight=1)
    textContainer.grid_columnconfigure(0, weight=1)
    textContainer.grid_columnconfigure(2, weight=1)
Reply
#2
I get errors with your code so can not run it
1) tkinter or tk has not been declared depending on how you import
2) the frame doesn't show up
Reply
#3
(Jun-18-2019, 04:15 PM)woooee Wrote: I get errors with your code so can not run it 1) tkinter or tk has not been declared depending on how you import 2) the frame doesn't show up
Brother this is not the complete code, this is a functionality. You have to add lines to make it work.I need to know how I can have a single scrollbar to move two text area.
Reply
#4
@smabubakkar if you had added a mini-functional example you might get an answer quicker as some folks need to play with it a bit to make sure they are giving the correct answer without that it means they have to spend extra time making their own mini-program to insert your code snippet into and then that does mean that they will do it the same way you did which means again not being able to give a correct answer. So you might want to consider updating your original post with a functioning mini-program that shows what you have.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] horizontal scrollbar on treeview is not working Vokofe 3 954 Oct-27-2025, 03:13 PM
Last Post: Vokofe
  [Tkinter] Help create scrollbar in chatbot with tkinter on python fenec10 6 7,286 Aug-28-2025, 10:38 AM
Last Post: fazanbabar82
  [Tkinter] Scrollbar apffal 7 5,684 Oct-11-2021, 08:26 PM
Last Post: deanhystad
Question [Tkinter] How to configure scrollbar dimension? water 6 6,412 Jan-03-2021, 06:16 PM
Last Post: deanhystad
  [PyQt] scrollbar in tab issac_n 1 5,548 Aug-04-2020, 01:33 PM
Last Post: deanhystad
  [Tkinter] Scrollbar in tkinter PatrickNoir 2 5,414 Jul-26-2020, 06:02 PM
Last Post: deanhystad
  [Tkinter] Help with Scrollbar JJota 6 6,145 Mar-10-2020, 05:25 AM
Last Post: Larz60+
  [Tkinter] Scrollbar doesn't work on Canvas in Tkinter DeanAseraf1 3 13,129 Sep-19-2019, 03:26 PM
Last Post: joe_momma
  Scrollbar rturus 5 25,323 Jun-06-2019, 01:04 PM
Last Post: heiner55
  [PyGUI] Create a scrollbar in GUI to add test cases mamta_parida 1 4,785 Sep-27-2018, 11:57 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020