1. 程式人生 > >Python3.4 tkinter GUI程式設計示例

Python3.4 tkinter GUI程式設計示例

新版的Python和tkinter 的程式編碼寫法和舊版本有所不同

from tkinter import *
import tkinter as tk

class Application():
	def __init__(self,  root):
		self.root=root
		self.root.bind("<KeyPress>",self.bind_key)
		self.root.bind("<KeyPress-Shift_R>",self.bind_r_key)

		
	def bind_key(self,event):
		print(event.keysym," key is pressed")
		
	def bind_r_key(self,event):
		print("the right Shift key has been pressed")
		

if __name__=="__main__":

	root=tk.Tk()
	root.title("KEY")
	Application(root)
	root.mainloop()