From tkinter Import *root = Tk () #定义按钮的回调函数def Backcallbutton (): Print ("button callback function") #通过command属性指定回调函数Btn1 = button (Root, Te XT = "button", command = Backcallbutton). Pack () #显示Button的各个不同效果 #flat, Groove, raised, ridge, solid, or Sunkenbutton (root, Text = ' FLAT ', Relief=flat). Pack () button (Root,text = ' GROOVE ', Relief=groove). Pack () button (Root,text = ' raised ', relief =raised). Pack () button (Root,text = ' RIDGE ', Relief=ridge). Pack () button (Root,text = ' SOLID ', relief=solid). Pack () button (Root,text = ' SUNKEN ', Relief=sunken). Pack () #与Label一样, button can also display text and images at the same time, using properties Compoundbutton (Root,text = ' Botton ', compound = ' bottom ', bitmap = ' error '). Pack () Button (root,text = ' top ', compound = ' top ', bitmap = ' error '). Pack () button (Root,text = ' right ', compound = ' right ', bitmap = ' error '). Pack () button (Root,text = "Left", compound = ' left ', bitmap = ' ERROR '). Pack () Button (root,text = ' center ', compound = ' center ', bitmap = ' error '). Pack () def printeventinfo (event): PRI NT (' Event.time = ', event.time) print (' Event.type = ', Event.type) Print (' event '. Widgetid = ', event.widget) print (' event. Keysymbol = ', event.keysym) b = Button (Root,text = ' infomation ') #bind方法, establish the relationship between the event and the callback function (response function) B.bind ("<Return>", Printeventinfo) B.pack () #focus_set设置控件焦点b. Focus_set () Root.mainloop ()
Tkinter-button (1)