Hi,
this is, let's say, the second part of this thread: http://www.daniweb.com/forums/thread291657.html
I have managed to control two widgets with one scrollbar, but now I have realized that, althought the widgets can be controlled individually via the mouse wheel or the keyboard, I sometimes need individual controls for each widget.
This is tony's code from prevois thread:
try:
from Tkinter import *
except ImportError: ## Python 3
from tkinter import *
root = Tk()
class App:
def __init__(self,master):
scrollbar = Scrollbar(master, orient=VERTICAL)
self.b1 = Text(master, yscrollcommand=scrollbar.set)
self.b2 = Text(master, yscrollcommand=scrollbar.set)
scrollbar.config(command=self.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.b1.pack(side=LEFT, fill=BOTH, expand=1)
self.b2.pack(side=LEFT, fill=BOTH, expand=1)
def yview(self, *args):
self.b1.yview(*args)
self.b2.yview(*args)
app = App(root)
for item in range(0,40):
for i in range(item):
it=str(i)+' '
app.b1.insert(1.0,it)
app.b2.insert(1.0,it)
app.b1.insert(1.0,'\n')
app.b2.insert(1.0,'\n')
root.mainloop()
This is my try:
import tkinter.scrolledtext
try:
from Tkinter import *
except ImportError: ## Python 3
from tkinter import *
root = Tk()
class App:
def __init__(self,master):
scrollbar = Scrollbar(master, orient=VERTICAL)
self.b1 = tkinter.scrolledtext.ScrolledText(master, yscrollcommand=scrollbar.set)
self.b2 = tkinter.scrolledtext.ScrolledText(master, yscrollcommand=scrollbar.set)
scrollbar.config(command=self.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.b1.pack(side=LEFT, fill=BOTH, expand=1)
self.b2.pack(side=LEFT, fill=BOTH, expand=1)
def yview(self, *args):
self.b1.yview(*args)
self.b2.yview(*args)
app = App(root)
for item in range(0,40):
for i in range(item):
it=str(i)+' '
app.b1.insert(1.0,it)
app.b2.insert(1.0,it)
app.b1.insert(1.0,'\n')
app.b2.insert(1.0,'\n')
root.mainloop()
I changed the widgets to scrolled text idgets, but it causes a weird behavior in the scrollbar that affects both widgets.
Now, is there a way to scroll these widgets (either text or scrolledtext) without using a toolbar, for example, with buttons for up and down, or with the keyboard (pressing a key for scrolling up and another for scrolling down)?
Remember I'm using tkinter and python 3.x
Thank you.