Python Forum
tkinter - touchscreen, push the button like click the mouse
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter - touchscreen, push the button like click the mouse
#1
Hi,
I have PanelPC (Advantech) - Touchscreen computer with Windows10 Pro. Im build an app on Python to communicate with PLC Siemens via TCP. It's working super fine.
For human interface I use tkinter, but I have problem with buttons:
I want the buttons to react to a touchscreen push the same way as a mouse click. Now I need to slide the button a little to action.

Is it possible to do this?
baggroundcolor = "#3d6466"
    buttoncolor = "#28393a"
    buttonpushedcolor = "#badee2"
                   
    def button_giveme():                
        global window_output_bools        
        choosen = False
        if window_output_bools[0] == True:
            window_output_bools[0] = False
            choosen = True
            
        if window_output_bools[0] == False and choosen == False:
            window_output_bools[0] = True
        
    #def widget-----------------------------------------------
              
    root = tkinter.Tk()
    root.title("PK")    
    root.geometry('1366x720')
    root.state('zoomed')
    
    #canvas       
    canvas = tkinter.Canvas(root, width= 1366, height= 720, bg=baggroundcolor)
    canvas.pack(fill= tkinter.BOTH, expand= True)
    
    main_backgroundimage = tkinter.PhotoImage(file="C:/Users/OEM/Desktop/Program/Py/GUI/pkhd.png")    
    canvas.create_image((683, 370), image = main_backgroundimage)
    
    
    #buttons
    btn_givemethecard = tkinter.Button(
        canvas,
        text="Give me the card",
        font=("TkHeadingFont",12),
        bg=buttoncolor,
        fg="white",        
        activebackground=buttonpushedcolor,
        activeforeground="black",
        command=lambda:button_giveme()
        )   
   
    btn_givemethecard.place(x=90, y=240)   
    
    #run window app
    root.mainloop()                
Reply
#2
What window event is sent when you press the touch screen?
Reply
#3
If I touched the screen the event logg show me nothing, when I relased the screen I saw:
[Image: pushtehbutton.png]
touch screen
When I try with mouse I see (slide and click button):
[Image: mousesbutton.png]
mouseclick
Now I try with Kivy - button is working like I wanted.

Has Kivy function like root.after? - I used this function to call communication function in loop.
Reply
#4
Kivy has the clock object that is used to schedule events. Or you could run run the communication function in a different thread.
John64 likes this post
Reply
#5
Thank You for help,
I just used from kivy.clock import Clock - Clock.schedule_interval(self.communication,0.1) - it's working
In first way i used communication as main process and tkinter as child process, but with Kivy when I started child process as Kivvy i have two window's. So I make now Kivy the main process and communication as a child process.
I'm just ordinary auotmation guy, but I just started with Python.
Reply
#6
Tkinter does not work well if it is not the main thread.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter Radio button group not setting default selection simonc88 3 800 Mar-20-2025, 06:53 PM
Last Post: buran
  Using place for a button, many examples but AttributeError, tkinter Edward_ 3 930 Dec-17-2024, 09:06 PM
Last Post: deanhystad
  Update Image on Button Click the_muffin_man 2 1,133 Nov-05-2024, 01:29 AM
Last Post: menator01
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 4,517 Jan-16-2024, 06:44 PM
Last Post: rob101
  Centering and adding a push button to a grid window, TKinter Edward_ 15 13,947 May-25-2023, 07:37 PM
Last Post: deanhystad
  Figure Gets Larger Every time I click a show button joshuagreineder 2 2,097 Aug-11-2022, 06:25 AM
Last Post: chinky
  Can't get tkinter button to change color based on changes in data dford 4 4,797 Feb-13-2022, 01:57 PM
Last Post: dford
  Creating a function interrupt button tkinter AnotherSam 2 8,017 Oct-07-2021, 02:56 PM
Last Post: AnotherSam
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 7,437 Oct-01-2021, 05:00 PM
Last Post: Yoriz
  tkinter showing image in button rwahdan 3 6,920 Jun-16-2021, 06:08 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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