Tkinter Course of event (1) '

Source: Internet
Author: User
Tags tkinter tutorial
"' Tkinter Tutorial event (1) '"
# How events are used
"' 1. Test mouse click (click) Event '
#-*-coding:cp936-*-
# <button-1&gt: Mouse left-click event
# <button-2&gt: Mouse-click event
# <button-3&gt: Mouse Right click event
# <double-button-1&gt: Double-click event
# <triple-button-1&gt: Three hit event
From Tkinter Import *
root = Tk ()
def printcoords (event):
Print Event.x,event.y
# Create the first button and bind it to the left event
BT1 = button (Root,text = ' leftmost button ')
Bt1.bind (' <Button-1> ', printcoords)

# Create two button and bind it to the middle key event
BT2 = button (Root,text = ' middle button ')
Bt2.bind (' <Button-2> ', printcoords)

# Create a third button and bind it to the right-click event
BT3 = button (Root,text = ' rightmost button ')
Bt3.bind (' <Button-3> ', printcoords)

# Create the fourth button and bind it to the double-click event
BT4 = Button (root,text = ' Double click ')
Bt4.bind (' <Double-Button-1> ', printcoords)

# Create the fifth button and bind it to the three-click event
Bt5 = Button (root, Text = ' Triple click ')
Bt5.bind (' <Triple-Button-1> ', printcoords)

Bt1.grid ()
Bt2.grid ()
Bt3.grid ()
Bt4.grid ()
Bt5.grid ()

Root.mainloop ()
# Test mouse events Separately, parameter of callback function event (x,y) indicates the coordinate value of the current click
"' 2. Test mouse Movement (Motion) event '
#-*-coding:cp936-*-
# <bx-motion&gt: Mouse move event, x=[1,2,3] represents the left, middle, and right mouse actions respectively.
From Tkinter Import *
root = Tk ()
def printcoords (event):
Print Event.x,event.y
# Create the first button and bind it to the left move event
BT1 = button (Root,text = ' leftmost button ')
Bt1.bind (' <B1-Motion> ', printcoords)

# Create two button and bind it to the middle key move event
BT2 = button (Root,text = ' middle button ')
Bt2.bind (' <B2-Motion> ', printcoords)

# Create a third button and bind it to the right-click Move Event
BT3 = button (Root,text = ' rightmost button ')
Bt3.bind (' <B3-Motion> ', printcoords)


Bt1.grid ()
Bt2.grid ()
Bt3.grid ()

Root.mainloop ()
# test Mouse movement events, only when the mouse is pressed to move back to generate events
' 3. Test mouse Release (relase) event '
#-*-coding:cp936-*-
# <ButtonRelease-x> Mouse Release event, x=[1,2,3], representing the left, middle, and right mouse actions
From Tkinter Import *
root = Tk ()
def printcoords (event):
Print Event.x,event.y
# Create the first button and bind it to the left-free event
BT1 = button (Root,text = ' leftmost button ')
Bt1.bind (' <ButtonRelease-1> ', printcoords)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.