介紹 Kivy;一個跨平臺的 Python 框架


在本文中,我們將學習 Kivy 框架及其安裝。Kivy 是基於 GUI 的應用程式介面,它是一個跨平臺的開源應用,適用於 Windows、Linux 和 Mac。

安裝指南

首先,我們需要在 PC 上安裝 Python。

然後,我們需要安裝依賴項 −

Windows −

>>> python -m pip install docutils pygments pypiwin32kivy.deps.sdl2 kivy.deps.glew
>>> python -m pip install kivy.deps.gstreamer
>>> python -m pip install kivy.deps.angle

Linux −

$ sudo add-apt-repository ppa:kivy-team/kivy

安裝 Kivy 檔案

Windows −

>>> python -m pip install kivy

Linux −

>>> sudo apt-get install python3-kivy

現在讓我們看看如何使用 Kivy 製作圖形使用者介面 −

示例

import kivy
kivy.require('1.10.0')
from kivy.app import App # gui interface creator
from kivy.uix.button import Label # button label import statement
class Sample(App):
   # display content on screen
   def build(self):
   # Return a label widget with Sample
   return Label(text ="Tutorialpoint")
sample = Sample()
sample.run()

輸出

將會顯示一個新視窗彈出視窗,標題為 Sample,其中包含文字“Tutorialspoint”。

螢幕上將會出現一個視窗彈出視窗

這樣,我們就可以使用 Kivy 在 Python 中建立基於 GUI 的應用程式

結論

在本文中,我們學習了使用 kivy 框架來建立基於 GUI 的應用程式。

更新日期:2019 年 8 月 28 日

735 次觀看

開啟你的職業生涯

透過完成課程獲得認證

開始
廣告