2016-03-29 17 views
0

我發現使用tk.Scrollbar可以使用觸摸文本小工具上的滾動。當我檢修應用程序的圖形時,我無法再使用觸摸來滾動使用ttk.Scrollbar的文本小部件。在tk.scrollbar上使用`ttk.scrollbar`時沒有滾動滾動

我很積極,它是兩個小部件之間的差異,因爲我在測試問題時已經在兩者之間切換。

這就是說這不是一個大問題,因爲只有少數這個程序將被安裝的設備將具有觸摸功能。

有沒有辦法聯繫到ttk.scrollbar

編輯:代碼的相關章節: 編輯#2:底部

self.text=tk.Text(self,font=("Consolas","11"),wrap="none",undo=True,bg="white",relief="flat") 
    self.numb=tk.Text(self,font=("Consolas","11"),wrap="none",width=4,relief="flat") 

    self.vsb=ttk.Scrollbar(self,command=self.scroller) 
    self.hsb=ttk.Scrollbar(self,command=self.text.xview,orient="horizontal") 

    self.text.configure(yscrollcommand=self.on_textscroll,xscrollcommand=self.hsb.set) 
    self.numb.config(bg="grey94",yscrollcommand=self.on_textscroll) 

def scroller(self,*args):#Move me 
    self.text.yview(*args) 
    self.numb.yview(*args) 
def on_textscroll(self, *args):#Move me 
    self.vsb.set(*args) 
    self.scroller('moveto', args[0]) 
+0

爲了正確得到這個結果。你指的是什麼「允許使用觸摸滾動」?在大多數設備中,touch實現使用「點擊」行爲。你的意思是它允許你點擊scrollbar-widget中的certan位置來將滑塊移動到那個方向/到那個位置? – R4PH43L

+0

@ R4PH43L對不起,我應該指定,這是使用觸摸文本小部件本身。通過這個,我的意思是像在文字文檔或記事本中那樣上下移動。它適用於滾動條是tk時,只是不ttk。 –

+2

好的。你可以發佈你在應用程序中使用的實現嗎? – R4PH43L

回答

0

(不一定是答案增加了兩個功能,但至少代碼進行實驗,也許建立在作出回答。)

下面的中間鼠標按鈕用tk(第2行註釋掉)或ttk滾動條(第2行未註釋)按住全部方向滾動。

from tkinter import Tk, Text, Scrollbar 
from tkinter.ttk import Scrollbar 

class Test(Tk): 
    def __init__(self): 
     super().__init__() 

     self.text = Text(self, wrap="none",undo=True,bg="white",relief="flat") 
     self.numb = Text(self, wrap="none",width=4,relief="flat") 

     self.vsb = Scrollbar(self,command=self.scroller) 
     self.hsb = Scrollbar(self,command=self.text.xview,orient="horizontal") 

     self.text.configure(yscrollcommand=self.on_textscroll,xscrollcommand=self.hsb.set) 
     self.numb.config(bg="grey94",yscrollcommand=self.on_textscroll) 

     self.numb.grid(row=0, column=0) 
     self.text.grid(row=0, column=1) 
     self.vsb.grid(row=0, column=2, sticky='ns') 
     self.hsb.grid(row=1, column=1, sticky='ew') 
     for i in range(100): 
      self.text.insert('insert', 
       ('abcdefg%2d '%i)*10 + '\n') 

    def scroller(self,*args):#Move me 
     self.text.yview(*args) 
     self.numb.yview(*args) 
    def on_textscroll(self, *args):#Move me 
     self.vsb.set(*args) 
     self.scroller('moveto', args[0]) 

root=Test() 

添加在初始化結束下面露出中間鼠標按鈕點擊(它是鈕2,不3)中,而無需禁用滾動效果。手指觸摸觸發這一點,無論是滾動?如果沒有,請嘗試找出觸摸產生的事件。

 def pr(event): 
      print(event) 
     self.text.bind('<Button-2>', pr) 
     self.text.bind('<ButtonRelease-2>', pr) 
+0

我已經完成了所有的按鈕選項,包括髮布和動作。他們什麼也沒透露是否有打印窗口小部件所涉及的所有事件的方法? –

+0

我瀏覽了http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/events.html中的部分,發現但不是。我的下一個猜測是,在觸摸系統上,手指觸摸和動作被定義爲虛擬事件。您可以嘗試'root.event_info()'在常規系統和觸摸系統上列出定義的虛擬事件,並查看後者是否有額外的事件。 http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/universal.html#event_info –