{"id":1163,"date":"2019-11-18T15:01:54","date_gmt":"2019-11-18T07:01:54","guid":{"rendered":"http:\/\/www.luwl.net\/?p=1163"},"modified":"2019-11-18T15:01:54","modified_gmt":"2019-11-18T07:01:54","slug":"python-tkinter%e7%9a%84%e5%85%a8%e5%b1%8f%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"http:\/\/www.luwl.net\/?p=1163","title":{"rendered":"python  tkinter\u7684\u5168\u5c4f\u4f7f\u7528"},"content":{"rendered":"\r\n<pre class=\"wp-block-code\"><code>import tkinter\r\nimport threading\r\n#\u6309F11\u5207\u6362\u5168\u5c4f\uff0cESC\u9000\u51fa\u5168\u5c4f\r\nclass FullScreenApp(object):\r\n    def __init__(self, master, **kwargs):\r\n        self.root = master\r\n        # self.tk.attributes('-zoomed', True)  # This just maximizes it so we can see the window. It's nothing to do with fullscreen.\r\n        self.frame = tkinter.Frame(self.root)\r\n        self.frame.pack()\r\n        self.state = False\r\n        self.root.bind(\"&lt;F11>\", self.toggle_fullscreen)\r\n        self.root.bind(\"&lt;Escape>\", self.end_fullscreen)\r\n\r\n    def toggle_fullscreen(self, event=None):\r\n        self.state = not self.state  # Just toggling the boolean\r\n        self.root.attributes(\"-fullscreen\", self.state)\r\n        return \"break\"\r\n\r\n    def end_fullscreen(self, event=None):\r\n        self.state = False\r\n        self.root.attributes(\"-fullscreen\", False)\r\n        return \"break\"\r\n\r\nwin=tkinter.Tk()\r\nwin.title(\"\u5b9e\u65f6\u8fd0\u884c\u7a97\u53e3\")\r\n#\u6839\u636e\u663e\u793a\u5668\u5206\u8fa8\u7387\u81ea\u52a8\u5168\u5c4f\u7a97\u53e3\r\nw = win.winfo_screenwidth()\r\nh = win.winfo_screenheight()\r\nwin.geometry(\"%dx%d\" %(w,h))\r\nwin.attributes(\"-fullscreen\",True)\r\napp=FullScreenApp(win)\r\n\r\ndef fun_timer():\r\n    print('hello timer')   #\u6253\u5370\u8f93\u51fa\r\n    global timer  #\u5b9a\u4e49\u53d8\u91cf\r\n    timer = threading.Timer(2,fun_timer)   #60\u79d2\u8c03\u7528\u4e00\u6b21\u51fd\u6570\r\n    #\u5b9a\u65f6\u5668\u6784\u9020\u51fd\u6570\u4e3b\u8981\u67092\u4e2a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u65f6\u95f4\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u51fd\u6570\u540d\r\n    timer.start()    #\u542f\u7528\u5b9a\u65f6\u5668\r\n    \r\ntimer = threading.Timer(1,fun_timer)  #\u9996\u6b21\u542f\u52a8\r\ntimer.start()\r\n\r\ncv = tkinter.Canvas(win,background='white')\r\ncv.pack()\r\ncv.create_rectangle(30, 30, 200, 200,\r\n    outline='red', # \u8fb9\u6846\u989c\u8272\r\n    stipple = 'question', # \u586b\u5145\u7684\u4f4d\u56fe\r\n    fill=\"red\", # \u586b\u5145\u989c\u8272\r\n    width=5 # \u8fb9\u6846\u5bbd\u5ea6\r\n    )\r\ncv.create_oval(240, 30, 330, 200,\r\n    outline='yellow', # \u8fb9\u6846\u989c\u8272\r\n    fill='pink', # \u586b\u5145\u989c\u8272\r\n    width=4 # \u8fb9\u6846\u5bbd\u5ea6\r\n    )\r\ncv.create_rectangle(50, 20, 150, 80, fill=\"#476042\")\r\ncv.create_rectangle(65, 35, 135, 65, fill=\"yellow\")\r\ncv.create_line(0, 0, 50, 20, fill=\"#476042\", width=3)\r\ncv.create_line(0, 100, 50, 80, fill=\"#476042\", width=3)\r\ncv.create_line(150,20, 200, 0, fill=\"#476042\", width=3)\r\ncv.create_line(150, 80, 200, 100, fill=\"#476042\", width=3)\r\ncv.create_text(60,40,text= \"hi, i am string\", font = \"time 10 bold underline\", tags = \"string\")\r\n\r\npoints = [100, 140, 110, 110, 140, 100, 110, 90, 100, 60, 90, 90, 60, 100, 90, 110]\r\n\r\ncv.create_polygon(points, outline=\"#476042\", \r\n            fill='yellow', width=3)\r\n#img = tkinter.PhotoImage(file=\"1.jpg\")\r\n#cv.create_image(20,20, image=img)\r\n\r\nlabel = tkinter.Label(win,text = '\u7237\u6765\u4e86')\r\nlabel.pack()\r\n# win\uff1a\u7236\u7a97\u4f53\r\n# text\uff1a\u663e\u793a\u7684\u6587\u672c\u5185\u5bb9\r\n# bg\uff1a\u80cc\u666f\u8272\r\n# fg\uff1a\u5b57\u4f53\u989c\u8272\r\n# font\uff1a\u5b57\u4f53\r\n# wraplength\uff1a\u6307\u5b9atext\u6587\u672c\u4e2d\u591a\u5bbd\u4e4b\u540e\u6362\u884c\r\n# justify\uff1a\u8bbe\u7f6e\u6362\u884c\u540e\u7684\u5bf9\u9f50\u65b9\u5f0f\r\n# anchor\uff1a\u4f4d\u7f6e n\u5317\uff0ce\u4e1c\uff0cw\u897f\uff0cs\u5357\uff0ccenter\u5c45\u4e2d\uff1b\u8fd8\u53ef\u4ee5\u5199\u5728\u4e00\u8d77\uff1ane\u4e1c\u5317\u65b9\u5411\r\nlabel = tkinter.Label(win,\r\n                      text=\"this is a word\",\r\n                      bg=\"pink\", fg=\"red\",\r\n                      font=(\"\u9ed1\u4f53\", 20),\r\n                      width=20,\r\n                      height=10,\r\n                      wraplength=100,\r\n                      justify=\"left\",\r\n                      anchor=\"ne\")\r\n\r\n# \u663e\u793a\u51fa\u6765\r\nlabel.pack()\r\n\r\n\r\nli     = ['C','python','php','html','SQL','java']\r\nmovie  = ['CSS','jQuery','Bootstrap']\r\nlistb  = tkinter.Listbox(win)          #  \u521b\u5efa\u4e24\u4e2a\u5217\u8868\u7ec4\u4ef6\r\nlistb2 = tkinter.Listbox(win)\r\nfor item in li:                 # \u7b2c\u4e00\u4e2a\u5c0f\u90e8\u4ef6\u63d2\u5165\u6570\u636e\r\n    listb.insert(0,item)\r\n \r\nfor item in movie:              # \u7b2c\u4e8c\u4e2a\u5c0f\u90e8\u4ef6\u63d2\u5165\u6570\u636e\r\n    listb2.insert(0,item)\r\n \r\nlistb.pack()                    # \u5c06\u5c0f\u90e8\u4ef6\u653e\u7f6e\u5230\u4e3b\u7a97\u53e3\u4e2d\r\nlistb2.pack()\r\n\r\nlabel1 = tkinter.Label(win, text=\"\u67f3\u591a\u598d\", bg=\"pink\")\r\n\r\nlabel2 = tkinter.Label(win, text=\"\u591a\u591a\", bg=\"yellow\")\r\n\r\nlabel3 = tkinter.Label(win, text=\"\u8d85\u7ea7\u98de\u4fa0\", bg=\"red\")\r\n\r\n# label1.pack()   # #\u9ed8\u8ba4\u6ca1\u6709\u5e03\u5c40\uff0c\u5b57\u6709\u591a\u957f\uff0c\u80cc\u666f\u4e5f\u6709\u591a\u957f\uff0c\u548c\u5176\u4ed6label\u9519\u843d\u663e\u793a\r\n# label2.pack()\r\n# label3.pack()\r\n\r\nlabel1.place(x=10, y=10)   # #\u56fa\u5b9a\u5750\u6807\uff0c\u6309\u7edd\u5bf9\u5e03\u5c40\u663e\u793a\uff0c\u7a97\u53e3\u5927\u5c0f\u7684\u53d8\u5316\u5bf9\u5e03\u5c40\u6ca1\u6709\u5f71\u54cd\r\nlabel2.place(x=50, y=50)\r\nlabel3.place(x=100, y=100)\r\n\r\n\r\n\r\nlabel1.config(text=\"NEW\")\r\n\r\n\r\nwin.mainloop()\r\n<\/code><\/pre>\r\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1163","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/posts\/1163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.luwl.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1163"}],"version-history":[{"count":1,"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/posts\/1163\/revisions"}],"predecessor-version":[{"id":1164,"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/posts\/1163\/revisions\/1164"}],"wp:attachment":[{"href":"http:\/\/www.luwl.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.luwl.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1163"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.luwl.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}