{"id":2006,"date":"2022-12-01T22:55:05","date_gmt":"2022-12-01T14:55:05","guid":{"rendered":"https:\/\/qaqaq.top\/?p=2006"},"modified":"2022-12-01T22:55:07","modified_gmt":"2022-12-01T14:55:07","slug":"%e4%bd%bf%e7%94%a8%e5%9c%a8for%ef%bc%88tkinter-python%ef%bc%89%e4%b8%ad%e5%88%9b%e5%bb%ba%e7%9a%84stringvar%e6%98%be%e7%a4%ba%e5%a4%9a%e4%b8%aa%e7%bb%84%e5%90%88%e6%a1%86%e7%9a%84%e9%bb%98%e8%ae%a4","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=2006","title":{"rendered":"\u4f7f\u7528\u5728for\uff08tkinter python\uff09\u4e2d\u521b\u5efa\u7684StringVar\u663e\u793a\u591a\u4e2a\u7ec4\u5408\u6846\u7684\u9ed8\u8ba4\u503c"},"content":{"rendered":"\n<p>\u6211\u60f3\u4ece\u5bf9\u8c61\u5217\u8868\uff08infos\uff09\u4e2d\u521b\u5efaComboBox\u3002\u6211\u521b\u5efa\u4e86\u4e0b\u9762\u7684\u7a0b\u5e8f\u3002\u6211\u7684\u95ee\u9898\u662f\u663e\u793a\u7ec4\u5408\u6846\u7684\u9ed8\u8ba4\u503c\u3002\u6211\u4f7f\u7528\u4e86\u4e00\u4e2aStringvar\u3002\u4f46\u9ed8\u8ba4\u503c\u4ec5\u663e\u793a\u5728\u4e0a\u6b21\u521b\u5efa\u7684\u7ec4\u5408\u6846\u4e2d\u3002\u6211\u8ba4\u4e3a\u8fd9\u662f\u56e0\u4e3a\u6211\u7684StringVar\u5bf9\u4e8e\u6240\u6709ComboBox\u90fd\u662f\u552f\u4e00\u7684\uff0c\u4f46\u6211\u4e0d\u77e5\u9053\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u6211\u8be5\u600e\u4e48\u505a<\/p>\n\n\n\n<p>\u8ba1\u6570\u5668=0<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for i in infos:\n        frame = Frame(principalFrame, bd=1)\n        frame.grid(row=counter, column=0, pady=20)\n        frame.columnconfigure(0,weight=1)\n\n        label = Label(frame, text=i.name)\n        label.grid(row=0, column=0, sticky=\"news\")\n        label.columnconfigure(0,weight=1)\n\n        varCombo = StringVar(window)\n        varCombo.set(i.default)\n\n        combo = ttk.Combobox(frame, state=\"readonly\", textvariable=varCombo, values=i.values)\n        combo.grid(row=1, column=0, sticky=\"news\")\n        combo.columnconfigure(0, weight=1)\n        combo.rowconfigure(0, weight=1)\n\n        counter = counter + 1<\/code><\/pre>\n\n\n\n<p>\u7531\u4e8e\u5bf9<code>StringVar<\/code>\u4f7f\u7528\u76f8\u540c\u7684\u53d8\u91cf<code>varCombo<\/code>\uff0c\u56e0\u6b64\u53ea\u6709<code>StringVar<\/code>\u7684\u6700\u540e\u4e00\u4e2a\u5b9e\u4f8b\u5f15\u7528\u4e86\u5b83\uff0c\u5176\u4ed6\u5b9e\u4f8b\u5c06\u88ab\u5783\u573e\u6536\u96c6<\/p>\n\n\n\n<p>\u5982\u679c\u60a8\u60f3\u7a0d\u540e\u8bbf\u95ee\u8fd9\u4e9b<code>StringVar<\/code>\uff0c\u6700\u597d\u4f7f\u7528\u5b57\u5178\u6765\u5b58\u50a8\u5b83\u4eec\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>varCombo = {}\ncounter = 0\nfor i in infos:\n    frame = Frame(principalFrame, bd=1)\n    frame.grid(row=counter, column=0, pady=20)\n    frame.columnconfigure(0,weight=1)\n\n    label = Label(frame, text=i.name)\n    label.grid(row=0, column=0, sticky=\"news\")\n    label.columnconfigure(0,weight=1)\n\n    var1 = StringVar(window)\n    var1.set(i.default)\n\n    combo = ttk.Combobox(frame, state=\"readonly\", textvariable=var1, values=i.values)\n    combo.grid(row=1, column=0, sticky=\"news\")\n    combo.columnconfigure(0, weight=1)\n    combo.rowconfigure(0, weight=1)\n    varCombo&#91;i.name] = var1\n\n    counter = counter + 1<\/code><\/pre>\n\n\n\n<p>combo=ttk.Combobox\uff08frame\uff0cstate=\u201creadonly\u201d\uff0ctextvariable=varCombo\uff0cvalues=i.values\uff09<\/p>\n\n\n\n<p>\u6bcf\u6b21\u5faa\u73af\u8fd0\u884c\u65f6\uff0c\u4e00\u4e2a\u65b0\u7684combobox\u88ab\u5206\u914d\u7ed9\u53d8\u91cfcombo\uff0c\u4f46combobox\u7684\u6700\u7ec8\u503c\u662f\u5728\u6700\u540e\u4e00\u6b21\u8fed\u4ee3\u4e2d\u8bbe\u7f6e\u7684\uff0c\u56e0\u6b64\uff0c\u53ea\u53cd\u6620\u6700\u540e\u4e00\u4e2a\u503c\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u7c7b\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002 \u8bf7\u67e5\u770b\u4ee5\u4e0b\u94fe\u63a5\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/6876518\/set-a-default-value-for-a-ttk-combobox\">Set a default value for a ttk Combobox<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u60f3\u4ece\u5bf9\u8c61\u5217\u8868\uff08infos\uff09\u4e2d\u521b\u5efaComboBox\u3002\u6211\u521b\u5efa\u4e86\u4e0b\u9762\u7684\u7a0b\u5e8f\u3002\u6211\u7684\u95ee\u9898\u662f\u663e\u793a\u7ec4\u5408\u6846\u7684\u9ed8\u8ba4\u503c\u3002\u6211\u4f7f\u7528\u4e86 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[45],"tags":[50],"class_list":["post-2006","post","type-post","status-publish","format-standard","hentry","category-python-","tag-python"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/2006"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2006"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/2006\/revisions"}],"predecessor-version":[{"id":2007,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/2006\/revisions\/2007"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}