在Ubuntu下创建Python图形界面,你可以选择多种库和框架。以下是一些流行的选择:
import tkinter as tk
root = tk.Tk()
root.title("Hello, World!")
label = tk.Label(root, text="Welcome to Python GUI with Tkinter")
label.pack()
root.mainloop()
pip install pyqt5
然后,你可以创建一个简单的PyQt5应用程序:
from PyQt5.QtWidgets import QApplication, QLabel, QWidget
app = QApplication([])
window = QWidget()
window.setWindowTitle("Hello, World!")
label = QLabel("Welcome to Python GUI with PyQt5", parent=window)
label.move(50, 50)
window.show()
app.exec_()
pip install kivy
然后,你可以创建一个简单的Kivy应用程序:
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text="Welcome to Python GUI with Kivy")
if __name__ == "__main__":
MyApp().run()
这些只是众多Python GUI库中的一部分。你可以根据自己的需求和喜好选择合适的库来创建图形界面。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>