{"id":432832,"date":"2021-04-18T16:45:53","date_gmt":"2021-04-18T08:45:53","guid":{"rendered":"http:\/\/4563.org\/?p=432832"},"modified":"2021-04-18T16:45:53","modified_gmt":"2021-04-18T08:45:53","slug":"%e9%81%87%e5%88%b0%e4%b8%80%e4%b8%aa-tkinter-%e4%ba%8b%e4%bb%b6%e7%bb%91%e5%ae%9a%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=432832","title":{"rendered":"\u9047\u5230\u4e00\u4e2a TKinter \u4e8b\u4ef6\u7ed1\u5b9a\u7684\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u9047\u5230\u4e00\u4e2a TKinter \u4e8b\u4ef6\u7ed1\u5b9a\u7684\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tars2018 <\/span>  <span><i><\/i> 5<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4e00\u4e2a\u8ba1\u7b97\u5668\u7a0b\u5e8f<\/p>\n<h1>&#8211;<em>&#8211; encoding: utf-8 &#8211;<\/em>&#8211;<\/h1>\n<p> <\/p>\n<p>&#8221;&#8217; @\u6587\u4ef6 :Caluators.py @\u8bf4\u660e : @\u65f6\u95f4 :2021-04-06 19:43:09 @\u4f5c\u8005 : @\u7248\u672c :1.0 &#8221;&#8217;<\/p>\n<p>import os,sys,time,logging import tkinter from typing import Text logging.basicConfig(level=logging.INFO)<\/p>\n<p>class Caluator(tkinter.Tk): def <strong>init<\/strong>(self, master=None): tkinter.Tk.<strong>init<\/strong>(self, master) self.caluator_str = [] self.createWidgets()<\/p>\n<pre><code>def createWidgets(self):     text_area= tkinter.Text(self)     text_area.config(width=120, height=5, bg=\"white\")     text_area.pack()      numbers_frame = tkinter.Frame(self, width=120, height=10)     numbers_frame.pack(ipadx=30, ipady=10)      button7 = tkinter.Button(numbers_frame, text=\"7\")     button7.config(font=\"-family {\u9ed1\u4f53} -size 18\")     button7.config(width=3, height=1)     button7.pack(side=\"left\", padx=10, pady=10)     button7.bind(\"&lt;Button-1&gt;\", self.caluator_func(7))      button8 = tkinter.Button(numbers_frame, text=\"8\")     button8.config(width=3, height=1)     button8.config(font=\"-family {\u9ed1\u4f53} -size 18\")     button8.pack(side=\"left\", padx=10)      button9 = tkinter.Button(numbers_frame, text=\"9\")     button9.config(width=3, height=1)     button9.config(font=\"-family {\u9ed1\u4f53} -size 18\")     button9.pack(side=\"left\", padx=10)      buttonc = tkinter.Button(numbers_frame, text=\"C\")     buttonc.config(width=3, height=1)     buttonc.config(font=\"-family {\u9ed1\u4f53} -size 18\")     buttonc.pack(side=\"left\", padx=10)      numbers_frame1 = tkinter.Frame(self, width=120, height=10)     numbers_frame1.pack(ipadx=20, ipady=10)      button4 = tkinter.Button(numbers_frame1, text=\"4\")     button4.config(width=3, height=1)     button4.config(font=\"-family {\u9ed1\u4f53} -size 18\")     button4.pack(side=\"left\", padx=10)      button5 = tkinter.Button(numbers_frame1, text=\"5\")     button5.config(width=3, height=1)     button5.config(font=\"-family {\u9ed1\u4f53} -size 18\")     button5.pack(side=\"left\", padx=10)      button6 = tkinter.Button(numbers_frame1, text=\"6\")     button6.config(width=3, height=1)     button6.config(font=\"-family {\u9ed1\u4f53} -size 18\")     button6.pack(side=\"left\", padx=10)      buttondcr = tkinter.Button(numbers_frame1, text=\"\/\")     buttondcr.config(width=3, height=1)     buttondcr.config(font=\"-family {\u9ed1\u4f53} -size 18\")     buttondcr.pack(side=\"left\", padx=10)          numbers_frame2 = tkinter.Frame(self, width=120, height=10)     numbers_frame2.pack(ipadx=20, ipady=10)      button1 = tkinter.Button(numbers_frame2, text=\"1\")     button1.config(width=3, height=1)     button1.config(font=\"-family {\u9ed1\u4f53} -size 18\")     button1.pack(side=\"left\", padx=10)      button2 = tkinter.Button(numbers_frame2, text=\"2\")     button2.config(width=3, height=1)     button2.config(font=\"-family {\u9ed1\u4f53} -size 18\")     button2.pack(side=\"left\", padx=10)      button3 = tkinter.Button(numbers_frame2, text=\"3\")     button3.config(width=3, height=1)     button3.config(font=\"-family {\u9ed1\u4f53} -size 18\")     button3.pack(side=\"left\", padx=10)      buttonplus = tkinter.Button(numbers_frame2, text=\"*\")     buttonplus.config(width=3, height=1)     buttonplus.config(font=\"-family {\u9ed1\u4f53} -size 18\")     buttonplus.pack(side=\"left\", padx=10)      numbers_frame3 = tkinter.Frame(self, width=120, height=10)     numbers_frame3.pack(ipadx=20, ipady=10)      button0 = tkinter.Button(numbers_frame3, text=\"0\")     button0.config(width=3, height=1)     button0.config(font=\"-family {\u9ed1\u4f53} -size 18\")     button0.pack(side=\"left\", padx=10)      buttond = tkinter.Button(numbers_frame3, text=\".\")     buttond.config(width=3, height=1)     buttond.config(font=\"-family {\u9ed1\u4f53} -size 18\")     buttond.pack(side=\"left\", padx=10)      buttonr = tkinter.Button(numbers_frame3, text=\"&lt;-\")     buttonr.config(width=3, height=1)     buttonr.config(font=\"-family {\u9ed1\u4f53} -size 18\")     buttonr.pack(side=\"left\", padx=10)      buttone = tkinter.Button(numbers_frame3, text=\"=\")     buttone.config(width=3, height=1)     buttone.config(font=\"-family {\u9ed1\u4f53} -size 18\")     buttone.pack(side=\"left\", padx=10)  def caluator_func(self, numbers):     self.caluator_str.append(numbers)     print(numbers) <\/code><\/pre>\n<p>if <strong>name<\/strong>==&#8221;<strong>main<\/strong>&#8220;: app = Caluator() app.title(&#8220;\u79d1\u5b66\u8ba1\u7b97\u5668&#8221;) app.geometry(&#8220;280&#215;400+120+200&#8221;) app.mainloop()<\/p>\n<p>\u76f4\u63a5\u8fd0\u884c\uff0c\u4f1a\u8f93\u51fa 7\uff0c\u4f46\u662f\u70b9\u51fb 7 \u8fd9\u4e2a\u6309\u94ae\uff0c\u4e0d\u4f1a\u8f93\u51fa 7\uff0c\u8bf7\u95ee\u662f\u54ea\u91cc\u51fa\u4e86\u95ee\u9898\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5671024\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             bind \u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5e94\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u4e14\u5728\u6bcf\u6b21\u70b9\u51fb\u6309\u94ae\u65f6\u88ab\u6309\u4e0b<br \/>\u4f46\u4f60\u8fd9\u91cc\u662f\u4e00\u65e6\u542f\u52a8\u4f1a\u8c03\u7528\u4e00\u6b21 self.caluator_func(7)\uff0c\u628a\u5f97\u5230\u7684 None \u7ed1\u5b9a\u5230\u6309\u94ae\u4e0a<br \/>\u53ef\u4ee5 button7.bind(&#8220;&lt;Button-1&gt;&#8221;, functools.partial(self.caluator_func, 7))<br \/>\u6216\u8005 lambda\uff0c\u6216\u8005\u4e3a\u6bcf\u4e2a\u6309\u94ae\u5355\u72ec\u8bbe\u7f6e\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5671025\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : tars2018 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy \u8c22\u8c22\uff0c\u4e3b\u8981\u662f\u60f3\u83b7\u53d6\u83b7\u53d6\u6309\u94ae\u7684 text \u5c5e\u6027\uff0c\u5df2\u89e3\u51b3\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u9047\u5230\u4e00\u4e2a TKinter \u4e8b\u4ef6\u7ed1\u5b9a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/432832"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=432832"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/432832\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=432832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=432832"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=432832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}