{"id":413,"date":"2022-07-07T10:04:38","date_gmt":"2022-07-07T10:04:38","guid":{"rendered":"http:\/\/fanaticboy.com\/?p=413"},"modified":"2022-07-07T10:04:38","modified_gmt":"2022-07-07T10:04:38","slug":"python%e4%b9%8btkinter%e8%bf%9b%e9%98%b6-%e6%89%b9%e9%87%8f%e4%bf%ae%e6%94%b9%e6%96%87%e4%bb%b6%e5%90%8e%e7%bc%80%e5%90%8d","status":"publish","type":"post","link":"https:\/\/fanaticboy.com\/?p=413","title":{"rendered":"python\u4e4btkinter\u8fdb\u9636-\u6279\u91cf\u4fee\u6539\u6587\u4ef6\u540e\u7f00\u540d"},"content":{"rendered":"\n<p>\u200b<\/p>\n\n\n\n<p>\u76f8\u4fe1\u5927\u5bb6tkinter\u7684\u57fa\u7840\u5df2\u7ecf\u6253\u597d\u4e86\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u8bf4\u4e00\u4e0btkinter\u5173\u4e8e\u6587\u4ef6\u64cd\u4f5c\u7684\u4e00\u4e9b\u5185\u5bb9\u3002\u5927\u5bb6\u90fd\u5728windows\u64cd\u4f5c\u8fc7\u9009\u62e9\u6587\u4ef6\uff0c\u9009\u62e9\u6216\u4e0a\u4f20\uff0c\u4e00\u822c\u662f\u56fe\u7247\u6bd4\u8f83\u591a\u3002\u6216\u4e0b\u8f7d\u7684\u65f6\u5019\u8ba9\u4f60\u9009\u62e9\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u63a5\u4e0b\u6765\u5c31\u7528tkinter\u5b9e\u73b0\u4e00\u4e0b\u6587\u4ef6\u9009\u62e9\u6279\u91cf\u4fee\u6539\u6587\u4ef6\u540e\u7f00\u540d\u3002<\/p>\n\n\n\n<p>\u4e00\u3001\u57fa\u672c\u51c6\u5907\u5de5\u4f5c\u5bfc\u5165\u5e93<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport tkinter.filedialog\nfrom tkinter import *<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"15\" src=\"blob:http:\/\/fanaticboy.com\/626d48c6-4cc1-4c76-a060-6d4dae66b844\" width=\"15\"><\/p>\n\n\n\n<p>\u4e8c\u3001\u521b\u5efa\u7c7bChange\uff0c\u6784\u9020\u51fd\u6570\u4e2d\u5b9a\u4e49\u754c\u9762<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Change:\n    def __init__(self):\n        root = Tk()\n        root.geometry(\"600x400+450+150\")\n        label = Label(root, text=\"\u8f93\u5165\u8981\u6539\u7684\u540e\u7f00\u540d\uff0c\u5305\u542b'.'\")\n        label.place(x=150, y=100)\n        self.u = StringVar()\n        text = Entry(root, textvariable=self.u)\n        text.place(x=310, y=100)\n        btn = Button(root, text=\"\u70b9\u51fb\u4fee\u6539\", command=self.change)\n        btn.place(x=330, y=150)\n        root.mainloop()<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"15\" src=\"blob:http:\/\/fanaticboy.com\/57ff30a2-f6a2-4217-981e-39d80436b814\" width=\"15\"><\/p>\n\n\n\n<p>\u4ee5\u4e0a\u7684\u4ee3\u7801\u5c31\u662f\u6784\u9020\u4e00\u4e2a\u53ef\u89c6\u5316\u7684\u754c\u9762\uff0c\u4e4b\u524d\u5728tkinter\u6a21\u5757\u4e2d\u5df2\u7ecf\u8bb2\u89e3\u4e86\u57fa\u672c\u7684\u7528\u6cd5\uff0c\u8fd9\u91cc\u5c31\u4e0d\u8fc7\u591a\u7684\u8fdb\u884c\u8bb2\u89e3\u4e86<\/p>\n\n\n\n<p>\u4e09\u3001\u5199\u9009\u62e9\u6587\u4ef6\u51fd\u6570\uff0c\u8fd9\u4e2a\u662f\u201c\u70b9\u51fb\u4fee\u6539\u201d\u7684\u529f\u80fd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def change(self):\n        a = tkinter.filedialog.askopenfilenames()  # \u53ef\u4ee5\u8fd4\u56de\u591a\u4e2a\u6587\u4ef6\u540d\n        print(a)\n        for i in a:\n            exe = os.path.splitext(i)  # \u5c06\u6587\u4ef6\u540e\u7f00\u4e0e\u6587\u4ef6\u5206\u5f00\n            new_name = exe&#91;0] + self.u.get()  # \u62fc\u63a5\u6210\u65b0\u7684\u540d\u5b57\n            os.rename(i, new_name)  # \u91cd\u547d\u540d\n            print(exe)<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"15\" src=\"blob:http:\/\/fanaticboy.com\/d560e5ee-b34e-4714-8a39-75bdcd54e45e\" width=\"15\"><\/p>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5199\u5728\u4e0a\u9762\u6784\u9020\u51fd\u6570\u7684\u4e0b\u9762\uff0c\u5728\u540c\u4e00\u4e2a\u7c7b\u91cc\u9762\uff0c\u4e3b\u8981\u7684\u4f5c\u7528\u662f\u4fee\u6539\u6587\u4ef6\u540e\u7f00\u540d<\/p>\n\n\n\n<p>\u4e3b\u8981\u7684\u4ee3\u7801\u5df2\u7ecf\u5199\u5b8c\u4e86\uff0c\u8ba9\u54b1\u4eec\u6d4b\u8bd5\u4e00\u4e0b\uff0c\u5728\u6700\u5e95\u90e8\u5199\u4e0a\u4e3b\u51fd\u6570\uff0c\u8fd0\u884c\u5c31\u53ef\u4ee5\u4e86\uff0c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if __name__ == '__main__':\n    ch = Change()<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"15\" src=\"blob:http:\/\/fanaticboy.com\/95c8e389-629c-4d2a-a731-37bc0b4cf9a5\" width=\"15\"><\/p>\n\n\n\n<p>\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u8fd0\u884c\u540e\u7684\u6548\u679c<\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/48aacd0760efd975159884c4825859f6.png\">\u200b<img loading=\"lazy\" decoding=\"async\" height=\"15\" src=\"blob:http:\/\/fanaticboy.com\/bb81b4a3-7fe3-456c-8388-9795647c707c\" width=\"15\">\u7f16\u8f91<\/p>\n\n\n\n<p>\u5148\u8f93\u5165\u8981\u4fee\u6539\u7684\u540e\u7f00\u540d\uff0c\u6211\u8fd9\u91cc\u6539\u6210&#8221;.txt&#8221;\uff0c\u7136\u540e\u70b9\u51fb\u201c\u201d\u70b9\u51fb\u4fee\u6539<\/p>\n\n\n\n<p>\u7136\u540e\u9009\u62e9\u4f60\u8981\u4fee\u6539\u7684\u6587\u4ef6\uff0c\u53ef\u4ee5\u591a\u9009<\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/22da2cda25a4d37396dedecaa0a90849.png\">\u200b<img loading=\"lazy\" decoding=\"async\" height=\"15\" src=\"blob:http:\/\/fanaticboy.com\/33247db3-d2b6-43b5-aac4-897eb3ab37bd\" width=\"15\">\u7f16\u8f91<\/p>\n\n\n\n<p>\u9009\u62e9\u5b8c\u4e4b\u540e\uff0c\u70b9\u51fb\u6253\u5f00\uff0c\u5c31\u53ef\u4ee5\u4fee\u6539\u6210\u529f\u4e86<\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/c8fb6deb7c99b3d0e3467ebbba9d8207.png\">\u200b<img loading=\"lazy\" decoding=\"async\" height=\"15\" src=\"blob:http:\/\/fanaticboy.com\/2cfec401-9163-4774-afd4-ec64f91cae61\" width=\"15\">\u7f16\u8f91<\/p>\n\n\n\n<p>\u200b \u200b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u200b \u76f8\u4fe1\u5927\u5bb6tkinter\u7684\u57fa\u7840\u5df2\u7ecf\u6253\u597d\u4e86\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u8bf4\u4e00\u4e0btkinter\u5173\u4e8e\u6587\u4ef6\u64cd\u4f5c\u7684\u4e00\u4e9b\u5185\u5bb9\u3002\u5927\u5bb6\u90fd\u5728wi &#8230; <a title=\"python\u4e4btkinter\u8fdb\u9636-\u6279\u91cf\u4fee\u6539\u6587\u4ef6\u540e\u7f00\u540d\" class=\"read-more\" href=\"https:\/\/fanaticboy.com\/?p=413\" aria-label=\"\u9605\u8bfb python\u4e4btkinter\u8fdb\u9636-\u6279\u91cf\u4fee\u6539\u6587\u4ef6\u540e\u7f00\u540d\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,16],"tags":[],"class_list":["post-413","post","type-post","status-publish","format-standard","hentry","category-python","category-tkinter"],"_links":{"self":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts\/413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=413"}],"version-history":[{"count":1,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts\/413\/revisions"}],"predecessor-version":[{"id":414,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts\/413\/revisions\/414"}],"wp:attachment":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}