﻿{"id":1670,"date":"2020-08-02T17:49:51","date_gmt":"2020-08-02T09:49:51","guid":{"rendered":"https:\/\/www.linuxmi.com\/?p=1670"},"modified":"2020-08-02T17:58:33","modified_gmt":"2020-08-02T09:58:33","slug":"python-kivy-install","status":"publish","type":"post","link":"https:\/\/www.linuxmi.com\/python-kivy-install.html","title":{"rendered":"Python Kivy\u901f\u6210\u8bfe\u7a0b\uff1a\u4ecb\u7ecd\u548c\u5b89\u88c5"},"content":{"rendered":"<p>\u8fd9\u662f\u6211\u4eec\u5173\u4e8eKivy\u901f\u6210\u8bfe\u7a0b\u7684\u7b2c\u4e00\u7bc7\u6587\u7ae0\uff0c\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecdKivy\u548cKivy\u7684\u5b89\u88c5\u3002Kivy\u662f\u4e00\u4e2a\u5f00\u6e90\u3001\u8de8\u5e73\u53f0\u7684 Python\u6846\u67b6\uff0c\u7528\u4e8e\u5f00\u53d1\u5229\u7528\u521b\u65b0\u7684\u591a\u70b9\u89e6\u63a7\u7528\u6237\u754c\u9762\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u76ee\u7684\u662f\u5141\u8bb8\u5feb\u901f\u8f7b\u677e\u7684\u4ea4\u4e92\u8bbe\u8ba1\u548c\u5feb\u901f\u539f\u578b\u5236\u4f5c\uff0c\u540c\u65f6\u4f7f\u60a8\u7684\u4ee3\u7801\u53ef\u91cd\u7528\u548c\u90e8\u7f72\u3002Kivy\u662f\u7528Python\u548c Cython\u7f16\u5199\u7684\uff0c\u57fa\u4e8eOpenGL ES 2\uff0c\u652f\u6301\u5404\u79cd\u8f93\u5165\u8bbe\u5907\uff0c\u5e76\u5177\u6709\u4e30\u5bcc\u7684\u5c0f\u90e8\u4ef6\u5e93\u3002\u4f7f\u7528\u76f8\u540c\u7684\u4ee3\u7801\u5e93\uff0c\u60a8\u53ef\u4ee5\u9488\u5bf9Windows\u3001macOS\u3001Linux\u3001Android\u548ciOS\u3002\u6240\u6709\u7684Kivy\u5c0f\u90e8\u4ef6\u90fd\u6709\u591a\u70b9\u89e6\u63a7\u652f\u6301\u3002<\/p>\n<p><strong>\u5b89\u88c5<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662fUbuntu\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u5b89\u88c5\u3002\u540c\u6837\uff0c\u5728\u5b89\u88c5\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u5b89\u88c5kivy\u7684\u4f9d\u8d56\u9879\uff0c\u7136\u540e\u5b89\u88c5kivy\u3002<\/p>\n<p>\u6dfb\u52a0\u4e00\u4e2aPPA<\/p>\n<p>stable builds: $ sudo add-apt-repository ppa:kivy-team\/kivy<\/p>\n<p>nightly builds: $ sudo add-apt-repository ppa:kivy-team\/kivy-daily<\/p>\n<p>\u66f4\u65b0\u8f6f\u4ef6\u6e90<\/p>\n<p>$ sudo apt-get update<\/p>\n<p>\u5b89\u88c5 Kivy<\/p>\n<p>Python2 &#8211; python-kivy:<\/p>\n<p>$ sudo apt-get install python-kivy<\/p>\n<p>Python3 &#8211; python3-kivy:<\/p>\n<p>$ sudo apt-get install python3-kivy<\/p>\n<p>\u53ef\u9009\u793a\u4f8b\u5e93\u2014kivy-examples::<\/p>\n<p>$ sudo apt-get install kivy-examples<\/p>\n<p>\u5bf9\u4e8e\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\uff0c\u53ef\u4ee5\u67e5\u770b\u5b83\u4eec\u7684\u6587\u6863\uff0c<a href=\"https:\/\/kivy.org\/doc\/stable-1.10.1\/installation\/installation-windows.html\" target=\"_blank\" rel=\"noopener noreferrer\">Kivy installation<\/a>\u3002<\/p>\n<p>\u73b0\u5728\u8ba9\u6211\u4eec\u5728Kivy\u4e2d\u521b\u5efa\u7b2c\u4e00\u4e2a\u7a97\u53e3\uff0c\u8fd9\u662f\u5728Kivy\u4e2d\u521b\u5efa\u7b2c\u4e00\u4e2a\u57fa\u672c\u7a97\u53e3\u7684\u4ee3\u7801\u3002<\/p>\n<pre style=\"font-size: 1em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 1.2em 0px; line-height: 1.2em;\"><code style=\"font-size: 0.85em; overflow: auto; font-family: Consolas, Inconsolata, Courier, monospace; background: #292824; white-space: pre; overflow-x: auto; color: #a6a28c; margin: 0px 0.15em; display: block; border-radius: 3px; -moz-text-size-adjust: none; border: #cccccc 1px solid; padding: 0.5em;\"><span style=\"color: #b854d4;\"><span style=\"background-color: #292824;\">from<\/span><\/span> kivy.app <span style=\"color: #b854d4;\"><span style=\"background-color: #292824;\">import<\/span><\/span> App\r\n\r\napp = App()\r\napp.run()\r\n<\/code><\/pre>\n<p>\u5728\u9876\u90e8\uff0c\u6211\u4eec\u4ecekivy\u5bfc\u5165\u4e86App\u7c7b\uff0c\u4e4b\u540e\u6211\u4eec\u521b\u5efa\u4e86App\u7c7b\u7684\u5bf9\u8c61\uff0c\u8fd9\u4e2aApp\u7c7b\u662f\u521b\u5efa\u7a97\u53e3\u7684\u521d\u59cb\u70b9\u3002\u5728\u4f60\u9700\u8981\u8fd0\u884capp\u5bf9\u8c61\u4e4b\u540e\u3002\u8fd0\u884c\u4e4b\u540e\uff0c\u60a8\u5c06\u770b\u5230\u8fd9\u4e2a\u7ed3\u679c\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1671\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/08\/kivy.png\" alt=\"\" width=\"820\" height=\"655\" srcset=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/08\/kivy.png 820w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/08\/kivy-300x240.png 300w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/08\/kivy-768x613.png 768w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/08\/kivy-430x343.png 430w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><\/p>\n<p>\u73b0\u5728\u8ba9\u6211\u4eec\u6269\u5c55\u4ee3\u7801\u5e76\u5728Kivy\u4e2d\u521b\u5efa\u4e00\u4e2alabel\u5c0f\u90e8\u4ef6\u3002<\/p>\n<pre style=\"font-size: 1em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 1.2em 0px; line-height: 1.2em;\"><code style=\"font-size: 0.85em; overflow: auto; font-family: Consolas, Inconsolata, Courier, monospace; background: #292824; white-space: pre; overflow-x: auto; color: #a6a28c; margin: 0px 0.15em; display: block; border-radius: 3px; -moz-text-size-adjust: none; border: #cccccc 1px solid; padding: 0.5em;\"><span style=\"color: #b854d4;\"><span style=\"background-color: #292824;\">from<\/span><\/span> kivy.app <span style=\"color: #b854d4;\"><span style=\"background-color: #292824;\">import<\/span><\/span> App\r\n<span style=\"color: #b854d4;\"><span style=\"background-color: #292824;\">from<\/span><\/span> kivy.uix.label <span style=\"color: #b854d4;\"><span style=\"background-color: #292824;\">import<\/span><\/span> Label\r\n\r\n<span style=\"background-color: #292824;\"><span style=\"color: #b854d4;\">class<\/span> <span style=\"color: #999580;\">LinuxMi<\/span><span style=\"color: #b65611;\">(App)<\/span>:<\/span>\r\n    <span style=\"color: #6684e1;\"><span style=\"background-color: #292824;\"><span style=\"color: #b854d4;\">def<\/span> <span style=\"color: #999580;\">build<\/span><span style=\"color: #b65611;\">(self)<\/span>:<\/span><\/span>\r\n        <span style=\"color: #999580;\"><span style=\"background-color: #292824;\">#return Label(text = \"Hello Kivy Application\", font_size = '25sp')<\/span><\/span>\r\n       <span style=\"color: #b854d4;\"><span style=\"background-color: #292824;\">return<\/span><\/span> Label(text = <span style=\"color: #60ac39;\"><span style=\"background-color: #292824;\">'[color=ff3333]Hello[color=3333ff]Kivy Application[color=ff3333]www.linuxmi.com'<\/span><\/span> ,markup=<span style=\"color: #b854d4;\"><span style=\"background-color: #292824;\">True<\/span><\/span>,font_size = <span style=\"color: #60ac39;\"><span style=\"background-color: #292824;\">\"30sp\"<\/span><\/span>)\r\n\r\n<span style=\"color: #b854d4;\"><span style=\"background-color: #292824;\">if<\/span><\/span> __name__ == <span style=\"color: #60ac39;\"><span style=\"background-color: #292824;\">\"__main__\"<\/span><\/span>:\r\n    window = LinuxMi()\r\n    window.run()\r\n<\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\u4f60\u53ef\u4ee5\u770b\u5230\uff0c\u9996\u5148\u6211\u4eec\u5df2\u7ecf\u4ecekivy\u5bfc\u5165\u4e86\u6211\u4eec\u9700\u8981\u7684\u7c7b\uff0c\u57fa\u672c\u4e0a\u6211\u4eec\u5c06\u4f7f\u7528App\u7c7b\u548cLabel\u7c7b\u3002\u4e4b\u540e\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4eceapp\u7c7b\u6269\u5c55\u7684\u7a97\u53e3\u7c7b\u3002app\u7c7b\u662f\u4efb\u4f55kivy\u5e94\u7528\u7a0b\u5e8f\u7684\u8d77\u70b9\u3002<\/p>\n<pre style=\"font-size: 1em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 1.2em 0px; line-height: 1.2em;\"><code style=\"font-size: 0.85em; overflow: auto; font-family: Consolas, Inconsolata, Courier, monospace; background: #292824; white-space: pre; overflow-x: auto; color: #a6a28c; margin: 0px 0.15em; display: block; border-radius: 3px; -moz-text-size-adjust: none; border: #cccccc 1px solid; padding: 0.5em;\">    <span style=\"color: #6684e1;\"><span style=\"background-color: #292824;\"><span style=\"color: #b854d4;\">def<\/span> <span style=\"color: #999580;\">build<\/span><span style=\"color: #b65611;\">(self)<\/span>:<\/span><\/span>\r\n        <span style=\"color: #999580;\"><span style=\"background-color: #292824;\">#return Label(text = \"Hello Kivy Application\", font_size = '25sp')<\/span><\/span>\r\n       <span style=\"color: #b854d4;\"><span style=\"background-color: #292824;\">return<\/span><\/span> Label(text = <span style=\"color: #60ac39;\"><span style=\"background-color: #292824;\">'[color=ff3333]Hello[color=3333ff]Kivy Application[color=ff3333]www.linuxmi.com'<\/span><\/span> ,markup=<span style=\"color: #b854d4;\"><span style=\"background-color: #292824;\">True<\/span><\/span>,font_size = <span style=\"color: #60ac39;\"><span style=\"background-color: #292824;\">\"30sp\"<\/span><\/span>)\r\n<\/code><\/pre>\n<p>\u6b64\u65b9\u6cd5\u8fd4\u56de\u7a97\u53e3\u5185\u5bb9\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4e00\u4e2a\u7b80\u5355\u7684\u5f69\u8272\u6807\u7b7e\u8bf4Hello Kivy Application www.linuxmi.com\u3002<\/p>\n<p>\u8fd0\u884c\u5b8c\u6574\u7684\u4ee3\u7801\uff0c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1673\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/08\/kivy-1.png\" alt=\"\" width=\"820\" height=\"655\" srcset=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/08\/kivy-1.png 820w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/08\/kivy-1-300x240.png 300w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/08\/kivy-1-768x613.png 768w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/08\/kivy-1-430x343.png 430w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u662f\u6211\u4eec\u5173\u4e8eKivy\u901f\u6210\u8bfe\u7a0b\u7684\u7b2c\u4e00\u7bc7\u6587\u7ae0\uff0c\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecdKivy\u548cKivy\u7684\u5b89\u88c5\u3002Kivy\u662f\u4e00 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":1673,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1670","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-qita"],"aioseo_notices":[],"views":979,"_links":{"self":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/1670","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/comments?post=1670"}],"version-history":[{"count":3,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/1670\/revisions"}],"predecessor-version":[{"id":1675,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/1670\/revisions\/1675"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/media\/1673"}],"wp:attachment":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/media?parent=1670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/categories?post=1670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/tags?post=1670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}