What Are the Tkinter Events for Horizontal Edge Scrolling (In Linux)

Tkinter bind Shift-MouseWheel to horizontal scroll

You need to have the binding call your own function, and then have that function call the xview_scroll method of the widget:

self.bind('<Shift-MouseWheel>', self.scrollHorizontally) 
...

def scrollHorizontally(self, event):
self.log.xview_scroll((event.delta/120), "units")

You may need to adjust the number of units (or "pages") you want to scroll with each click of the wheel.

This answer has more information about platform differences with respect to the delta attribute of the event.

Checkbuttons within a scrolling Text spill over the top border

Set the borderwidth of the Text widget to zero. If you still want the "sunken" look, you can configure the outer frame.

How to identify non-printable KeyPress events in Tkinter

Question 1 and 2 :

I believe your method works, but it seems simpler to just use the str.isprintable method, it returns a boolean indicating whether or not the argument string isprintable:

>>> "aéûβß\\".isprintable() #Works with various accents, special characters
True
>>> "\x16".isprintable()
False
>>> "\n".isprintable() #Excludes all other characters
False

the method using len(repr(event.char) == 3 could work, but it would for instance, also exclude \, which has a repr of 4 chars ('\\').

Question 3 :

Like you said, there are a bunch of gotcha (eg: tab's event char is "\t", returns is "\r"... I don't know where/if you can find an exhaustive list of these particularities, the only solution I ever had was try out the most common (eg pretty much every key and combinason Ctrl+key on my keyboard, using a program of course:

chars = dict()
def LogKey(event, chars = chars): #dict is mutable
global char #get the actual value of char
dict[char] = event.char #

root = Tk()
root.bind("<KeyPress>", LogKey)

for character in "abcde...123456...²&é\"'(-è_...)": #and so on
char = character
root.event_generate("<KeyPress-{}>".format(character))
char = "<Control-{}>".format(character)
root.event_generate(char)
char = "<Control-Shift-{}>".format(character)
...
#Inspect the dictonary chars in the end

It's probably not the best method, but it should cover most cases, you can also expande to test multiple keys (eg Control-c-v)...



Related Topics



Leave a reply



Submit