提交 6acae97e 编写于 作者: W wizardforcel

2019-11-21 17:39:55

上级 8e37d40a
......@@ -4,7 +4,7 @@
如果您尚未安装 [PyQT5](https://pythonspot.com/pyqt5/) ,则应先安装。 在终端中,您可以输入:
```
```py
sudo apt-get install python3-pyqt5
```
......@@ -15,7 +15,7 @@ sudo apt-get install python3-pyqt5
You can create a **[PyQT5](https://pythonspot.com/pyqt5/)** window using the code below:
```
```py
import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QIcon
......@@ -47,7 +47,7 @@ if __name__ == '__main__':
运行:
```
```py
python3 window.py
```
......
......@@ -8,7 +8,7 @@ PyQt5 支持使用 QPushButton 类的按钮。 此类在 PyQt5.QtWidgets 组中
要将按钮用于 [PyQt5](https://pythonspot.com/pyqt5/) 应用程序,我们需要更新导入行:
```
```py
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtCore import pyqtSlot
......@@ -16,7 +16,7 @@ from PyQt5.QtCore import pyqtSlot
在 initUI()方法中,添加以下代码行:
```
```py
button = QPushButton('PyQt5 button', self)
button.setToolTip('This is an example button')
button.move(100,70)
......@@ -25,7 +25,7 @@ button.move(100,70)
QPushButton 创建小部件,第一个参数是按钮上的文本。 当用户将鼠标指向按钮时,setToolTip 方法显示消息。 最后,将按钮移动到坐标 x = 100,y = 70。 我们需要为按钮单击创建一种方法:
```
```py
@pyqtSlot()
def on_click(self):
print('PyQt5 button click')
......@@ -34,14 +34,14 @@ def on_click(self):
使用以下命令将连接方法添加到单击:
```
```py
button.clicked.connect(self.on_click)
```
最终 [PyQt5](https://pythonspot.com/pyqt5/) 按钮代码:
```
```py
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtGui import QIcon
......
......@@ -8,7 +8,7 @@
为了显示一个消息框,我们需要导入 **QMessageBox**
```
```py
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox
```
......@@ -19,7 +19,7 @@ from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox
复制以下代码以显示消息框。
```
```py
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox
from PyQt5.QtGui import QIcon
......@@ -59,7 +59,7 @@ if __name__ == '__main__':
考虑到我们使用 **QMessageBox。是****QMessageBox.No** 。 我们可以轻松添加其他选项:
```
```py
buttonReply = QMessageBox.question(self, 'PyQt5 message', "Do you want to save?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel, QMessageBox.Cancel)
print(int(buttonReply))
if buttonReply == QMessageBox.Yes:
......
......@@ -10,7 +10,7 @@
创建文本框非常简单:
```
```py
self.textbox = QLineEdit(self)
self.textbox.move(20, 20)
self.textbox.resize(280,40)
......@@ -23,7 +23,7 @@ self.textbox.resize(280,40)
下面的示例创建一个带有文本框的窗口。
```
```py
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QPushButton, QAction, QLineEdit, QMessageBox
from PyQt5.QtGui import QIcon
......
......@@ -6,7 +6,7 @@
可以使用 menuBar()方法创建顶部菜单。 子菜单添加了 addMenu(name) 示例:
```
```py
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('File')
editMenu = mainMenu.addMenu('Edit')
......@@ -19,7 +19,7 @@ helpMenu = mainMenu.addMenu('Help')
可以将单个按钮添加到菜单中,如下所示:
```
```py
exitButton = QAction(QIcon('exit24.png'), 'Exit', self)
exitButton.setShortcut('Ctrl+Q')
exitButton.setStatusTip('Exit application')
......@@ -32,7 +32,7 @@ fileMenu.addAction(exitButton)
完整代码:
```
```py
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QPushButton, QAction
from PyQt5.QtGui import QIcon
......
......@@ -12,14 +12,14 @@
## [](#Example "Example")范例
```
```py
from PyQt5.QtWidgets import QTableWidget,QTableWidgetItem
```
使用以下命令创建一个表:
```
```py
self.tableWidget = QTableWidget()
# set row count
......@@ -32,7 +32,7 @@ self.tableWidget.setColumnCount(2)
要添加单个单元格:
```
```py
self.tableWidget.setItem(X,Y, QTableWidgetItem("TEXT"))
```
......@@ -41,7 +41,7 @@ self.tableWidget.setItem(X,Y, QTableWidgetItem("TEXT"))
完整的 [**PyQt5**](https://pythonspot.com/pyqt5/) 表代码如下:
```
```py
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QAction, QTableWidget,QTableWidgetItem,QVBoxLayout
from PyQt5.QtGui import QIcon
......
......@@ -10,7 +10,7 @@
完整 [**PyQt5**](https://pythonspot.com/pyqt5/) 标签示例:
```
```py
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QWidget, QAction, QTabWidget,QVBoxLayout
from PyQt5.QtGui import QIcon
......@@ -76,14 +76,14 @@ if __name__ == '__main__':
要将表添加到窗口,我们创建一个新类:
```
```py
class MyTableWidget(QWidget)
```
我们通过为标签创建一个 **QTabWidget** 和两个 **QWidgets** 来初始化标签屏幕。
```
```py
self.tabs = QTabWidget()
self.tab1 = QWidget()
self.tab2 = QWidget()
......@@ -93,7 +93,7 @@ self.tabs.resize(300,200)
然后,我们将这些选项卡添加到选项卡小部件中:
```
```py
self.tabs.addTab(self.tab1,"Tab 1")
self.tabs.addTab(self.tab2,"Tab 2")
......@@ -101,7 +101,7 @@ self.tabs.addTab(self.tab2,"Tab 2")
使用以下命令创建选项卡的内容:
```
```py
self.tab1.layout = QVBoxLayout(self)
self.pushButton1 = QPushButton("PyQt5 button")
self.tab1.layout.addWidget(self.pushButton1)
......@@ -111,7 +111,7 @@ self.tab1.setLayout(self.tab1.layout)
最后,我们将标签添加到小部件中:
```
```py
self.layout.addWidget(self.tabs)
self.setLayout(self.layout)
......@@ -119,7 +119,7 @@ self.setLayout(self.layout)
不要忘记将您的自定义标签窗口小部件添加到窗口中:
```
```py
self.table_widget = MyTableWidget(self)
self.setCentralWidget(self.table_widget)
......
......@@ -12,7 +12,7 @@
我们将显示整个代码,然后进行解释。
```
```py
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QGroupBox, QDialog, QVBoxLayout
from PyQt5.QtGui import QIcon
......@@ -74,7 +74,7 @@ if __name__ == '__main__':
我们首先在 initUI()方法中调用 self.createHorizo​​ntalLayout()方法。 在方法内部,我们创建了一个带有标题和水平布局的框:
```
```py
self.horizontalGroupBox = QGroupBox("What is your favorite color?")
layout = QHBoxLayout()
......@@ -82,7 +82,7 @@ layout = QHBoxLayout()
我们创建小部件(在此示例中为 QPushButtons),并将它们一个接一个地添加到布局中:
```
```py
buttonBlue = QPushButton('Blue', self)
buttonBlue.clicked.connect(self.on_click)
layout.addWidget(buttonBlue)
......@@ -91,14 +91,14 @@ layout.addWidget(buttonBlue)
我们将标题框设置为包含水平布局:
```
```py
self.horizontalGroupBox.setLayout(layout)
```
在 initUI 方法中,我们将其添加到窗口中:
```
```py
windowLayout = QVBoxLayout()
windowLayout.addWidget(self.horizontalGroupBox)
self.setLayout(windowLayout)
......
......@@ -10,7 +10,7 @@
下面的示例创建网格:
```
```py
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QGroupBox, QDialog, QVBoxLayout, QGridLayout
from PyQt5.QtGui import QIcon
......@@ -68,14 +68,14 @@ if __name__ == '__main__':
我们通过以下方式导入 gridlayout 和其他内容:
```
```py
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QGroupBox, QDialog, QVBoxLayout, QGridLayout
```
在方法 createGridLayout()中,我们创建带有标题的网格并设置大小。
```
```py
def createGridLayout(self):
self.horizontalGroupBox = QGroupBox("Grid")
layout = QGridLayout()
......@@ -86,7 +86,7 @@ def createGridLayout(self):
使用添加小部件
```
```py
layout.addWidget(Widget,X,Y)
```
......
......@@ -4,7 +4,7 @@
[**PyQt5**](https://pythonspot.com/pyqt5/) 支持多个输入对话框,使用它们可以导入 QInputDialog。
```
```py
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit
```
......@@ -17,7 +17,7 @@ from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit
使用 QInputDialog.getInt()获取整数:
```
```py
def getInteger(self):
i, okPressed = QInputDialog.getInt(self, "Get integer","Percentage:", 28, 0, 100, 1)
if okPressed:
......@@ -31,7 +31,7 @@ def getInteger(self):
通过 QInputDialog.getDouble()获得双倍:
```
```py
def getDouble(self):
d, okPressed = QInputDialog.getDouble(self, "Get double","Value:", 10.05, 0, 100, 10)
if okPressed:
......@@ -45,7 +45,7 @@ def getDouble(self):
从下拉框中获取一个项目:
```
```py
def getChoice(self):
items = ("Red","Blue","Green")
item, okPressed = QInputDialog.getItem(self, "Get item","Color:", items, 0, False)
......@@ -58,7 +58,7 @@ def getChoice(self):
使用 QInputDialog.getText()获取字符串
```
```py
def getText(self):
text, okPressed = QInputDialog.getText(self, "Get text","Your name:", QLineEdit.Normal, "")
if okPressed and text != '':
......@@ -70,7 +70,7 @@ def getText(self):
下面的完整示例:
```
```py
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit
from PyQt5.QtGui import QIcon
......
......@@ -14,7 +14,7 @@
下面的代码将显示所有文件对话框:
```
```py
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog
from PyQt5.QtGui import QIcon
......
......@@ -8,7 +8,7 @@ PyQt5(和 Qt)默认情况下支持图像。 在本文中,我们将向您
将图像添加到 [PyQt5](https://pythonspot.com/pyqt5/) 窗口就像创建标签并将图像添加到该标签一样简单。
```
```py
label = QLabel(self)
pixmap = QPixmap('image.jpeg')
label.setPixmap(pixmap)
......@@ -20,7 +20,7 @@ self.resize(pixmap.width(),pixmap.height())
这些是必需的导入:
```
```py
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtGui import QIcon, QPixmap
......@@ -32,7 +32,7 @@ from PyQt5.QtGui import QIcon, QPixmap
复制下面的代码并运行。 该映像应与程序位于同一目录中。
```
```py
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtGui import QIcon, QPixmap
......
......@@ -14,7 +14,7 @@
This application will create a graphical window that can be minimized, maximimzed and resized it.
```
```py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
......@@ -42,21 +42,21 @@ sys.exit(a.exec_())
必须导入 [PyQT4](https://pythonspot.com/pyqt4/) 模块,我们通过以下代码行进行导入:
```
```py
from PyQt4.QtGui import *
```
我们使用 QApplication()创建 [PyQT4](https://pythonspot.com/pyqt4/) 应用程序对象:
```
```py
a = QApplication(sys.argv)
```
我们创建窗口(QWidget),调整大小,设置标题并显示以下代码:
```
```py
w = QWidget()
w.resize(320, 240)
w.setWindowTitle("Hello World!")
......@@ -65,7 +65,7 @@ w.setWindowTitle("Hello World!")
不要忘记显示窗口:
```
```py
# Show window
w.show()
......
......@@ -16,7 +16,7 @@ PyQt4(Qt4)通过 QPushButton 小部件支持按钮。
The example below adds a button to a PyQt4 window.
```
```py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
......@@ -55,7 +55,7 @@ A button click should do something. To do so, you must use signals and slots.
如果用户执行诸如单击按钮,在框中键入文本之类的操作,则小部件会发出信号。 信号可以与一个插槽相连,该插槽充当接收器并对其起作用。
```
```py
import sys
from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import *
......
......@@ -8,7 +8,7 @@
The code below will display a message box with two buttons:
```
```py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
......@@ -48,7 +48,7 @@ qtMessagebox question
You can display a warning box using this line of code:
```
```py
QMessageBox.warning(w, "Message", "Are you sure you want to continue?")
```
......@@ -57,7 +57,7 @@ QMessageBox.warning(w, "Message", "Are you sure you want to continue?")
We can display an information box using QMessageBox.information()
```
```py
QMessageBox.information(w, "Message", "An information messagebox @ pythonspot.com ")
```
......@@ -72,7 +72,7 @@ QMessageBox Info
If something goes wrong in your application you may want to display an error message.
```
```py
QMessageBox.critical(w, "Message", "No disk space left on device.")
```
......@@ -85,7 +85,7 @@ QMessagebox
We have shown the question box above.
```
```py
QMessageBox.about(w, "About", "An example messagebox @ pythonspot.com ")
```
......
......@@ -16,7 +16,7 @@ QMainWindow 类创建主应用程序窗口。 此类具有一个名为 menuBar
This code will add a menu to your qt4 app:
```
```py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
......
......@@ -14,7 +14,7 @@ For more widgets we suggest using the GUI creation tool covered in the next tuto
几乎每个应用程序中都存在输入字段。 在 [PyQT4](https://pythonspot.com/pyqt4/) 中,可以使用 QLineEdit()函数创建输入字段。
```
```py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
......@@ -53,7 +53,7 @@ qt textbox
组合框可用于从列表中选择一个项目。
```
```py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
......@@ -95,7 +95,7 @@ qt combobox
PyQT4 库有一个日历小部件,您可以使用 QCalendarWidget()调用来创建它。
```
```py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
......
......@@ -14,7 +14,7 @@ PyQt4 textbox example
The textbox example below changes the text if the button is pressed.
```
```py
import sys
from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import *
......@@ -52,7 +52,7 @@ app.exec_()
使用以下行创建文本字段:
```
```py
textbox = QLineEdit(w)
textbox.move(20, 20)
textbox.resize(280,40)
......@@ -61,14 +61,14 @@ textbox.resize(280,40)
该按钮(来自屏幕截图)由以下部分制成:
```
```py
button = QPushButton('Click me', w)
```
我们通过以下方式将按钮连接到 on_click 函数:
```
```py
# connect the signals to the slots
button.clicked.connect(on_click)
......
......@@ -8,7 +8,7 @@
An example below:
```
```py
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
......
......@@ -4,7 +4,7 @@
选项卡在图形应用程序中非常有用。 它们出现在网络浏览器,文本编辑器和任何其他应用中。 要创建选项卡式窗口,您需要调用 QTabWidget()函数。 每个选项卡都是您之前看到的 QWidget()。 您可以使用以下功能将 QWidget 与 QTabWidget 连接:
```
```py
tabs.addTab(tab1,"Tab 1")
```
......@@ -13,7 +13,7 @@ tabs.addTab(tab1,"Tab 1")
**示例代码:**
```
```py
from PyQt4 import QtGui
from PyQt4 import QtCore
import sys
......
......@@ -8,7 +8,7 @@
让我们从代码开始:
```
```py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
......
......@@ -12,7 +12,7 @@ An image loaded in a PyQt4 window.
The constructor of Pixmap takes the image path as parameter:
```
```py
pixmap = QPixmap(os.getcwd() + '/logo.png')
```
......@@ -23,7 +23,7 @@ pixmap = QPixmap(os.getcwd() + '/logo.png')
We create a standard QWidget as we have done before. Then we add the QPixmap widget inside which will load the image. The Pixmap is attached to a label which is drawn to the screen.
```
```py
import os
import sys
from PyQt4.QtGui import *
......
......@@ -8,21 +8,21 @@
要在 [PyQT](https://pythonspot.com/pyqt4/) 中获取文件名(而非文件数据),可以使用以下行:
```
```py
filename = QFileDialog.getOpenFileName(w, 'Open File', '/')
```
如果您使用的是 Microsoft Windows,请使用
```
```py
filename = QFileDialog.getOpenFileName(w, 'Open File', 'C:\')
```
下面的示例(包括加载文件数据):
```
```py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
......
......@@ -10,7 +10,7 @@ PyQt does not include Qt itself – you may have to obtain it separately. The ho
您将需要安装一些软件包:
```
```py
sudo pip install pyqt
sudo apt-get install qt4-designer
sudo apt-get install pyqt4-dev-tools
......@@ -36,7 +36,7 @@ QT KDE Dialog
文件 test.ui 包含以 XML 格式描述的表单。 (您可以在文本编辑器中查看它)打开控制台并键入:
```
```py
pyuic4 form.ui > form.py
```
......@@ -45,7 +45,7 @@ pyuic4 form.ui > form.py
粘贴以下代码:
```
```py
import sys
from PyQt4 import QtCore, QtGui
from form import Ui_Dialog
......@@ -66,7 +66,7 @@ if __name__ == "__main__":
运行:
```
```py
python gui.py
```
......@@ -79,7 +79,7 @@ python gui.py
我们想在按下 OK 按钮时添加一些动作。 我们将以下三行添加到代码中:
```
```py
self.ui.pushButton.clicked.connect(self.OK)
def OK(self):
......
......@@ -8,7 +8,7 @@
An excerpt of user interface markup [graphical user interfaces](https://pythonspot.com/gui/) and language code could look like:
```
```py
Rectangle {
id: simplebutton
color: "grey"
......@@ -50,14 +50,14 @@ draganddrop
我们将图像拖到该区域上,然后选择右侧的源。 保存项目。 打开终端并找到您刚创建的 qml 文件。 或者,您可以简单地将代码复制到编辑框中,然后将其保存到.qml 文件中。 输入命令:
```
```py
qmlviewer main.qml
```
这将显示 qml 文件中定义的窗口,没有任何功能。 它只是界面的查看器。 然后,我们创建一些代码来加载此 QML 定义:
```
```py
import sys
from PyQt4.QtCore import QDateTime, QObject, QUrl, pyqtSignal
......@@ -79,14 +79,14 @@ app.exec_()
最后,我们将第一行 main.qml 修改为:
```
```py
import Qt 4.7
```
仅仅是因为我们的 QtQuick 不见了。 跑步
```
```py
python run.py
```
......
......@@ -4,7 +4,7 @@
带有 onClick 事件的 **Tk 按钮** 要创建带有按钮的 [**Tkinter**](https://pythonspot.com/tkinter/) 窗口,请使用以下示例。 程序进入 mainloop(),等待事件(用户操作)。 我们定义具有回调函数 callback()的按钮。 master 是根窗口,您的按钮将出现在该窗口中。
```
```py
from Tkinter import *
master = Tk()
......@@ -27,7 +27,7 @@ tk button
如果需要图像按钮,请使用 PhotoImage 类。 我们使用函数 minsize()和 geometry()设置窗口的大小和最小大小。 例:
```
```py
from Tkinter import *
master = Tk()
......@@ -55,7 +55,7 @@ tk image button
如果需要图像和文本,只需添加参数 compound = LEFT。
```
```py
from Tkinter import *
master = Tk()
......@@ -83,7 +83,7 @@ tk button with text and image
如果要将按钮放置在坐标上,请不要使用 pack()函数,而要使用 place(x,y)函数,如下例所示:
```
```py
from Tkinter import *
master = Tk()
......
......@@ -14,7 +14,7 @@ Tkinter menu
You can create a simle menu with [Tkinter](https://pythonspot.com/tkinter/) using the code below. Every option (new, open, save.. ) should have its own callback.
```
```py
from Tkinter import *
def donothing():
......@@ -43,7 +43,7 @@ root.mainloop()
我们通过调用创建菜单栏:
```
```py
menubar = Menu(root)
```
......@@ -54,7 +54,7 @@ menubar = Menu(root)
可以使用相同的 Menu()调用创建子菜单,其中第一个参数是要附加到的菜单栏。
```
```py
filemenu = Menu(menubar, tearoff=0)
menu = Menu(menubar, tearoff=0)
......@@ -62,7 +62,7 @@ menu = Menu(menubar, tearoff=0)
可以使用 add_command()方法将各个选项添加到这些子菜单中:
```
```py
filemenu.add_command(label="New", command=donothing)
filemenu.add_command(label="Open", command=donothing)
filemenu.add_command(label="Save", command=donothing)
......
......@@ -15,7 +15,7 @@
要创建标签,我们只需调用 Label()类并将其打包。 padx 和 pady 是水平和垂直填充。
```
```py
from Tkinter import *
root = Tk()
......@@ -30,7 +30,7 @@ root.mainloop()
要获取用户输入,可以使用条目小部件。
```
```py
from Tkinter import *
root = Tk()
......@@ -55,7 +55,7 @@ tk entry
Tk 具有一个小部件来显示图像,即 PhotoImage。 加载图像非常容易:
```
```py
from Tkinter import *
import os
......
......@@ -6,7 +6,7 @@
适用于 Python 2.7 的 [**Tkinter**](https://pythonspot.com/tkinter/) 和 Python 3 之间略有不同。 要找到您的 Python 版本,请尝试以下命令之一:
```
```py
python --version
python3 --version
......@@ -26,7 +26,7 @@ Tkinter 包括其他几个消息框:
<u>Python 3.x</u>
```
```py
import tkinter
from tkinter import messagebox
......@@ -43,7 +43,7 @@ messagebox.showinfo("Information","Informative message")
<u>Python 2.7</u>
```
```py
import Tkinter
import tkMessageBox
......
......@@ -22,7 +22,7 @@
|
```
```py
from Tkinter import *from Tkinter import *
import Tkinter, Tkconstants, tkFileDialog
......@@ -36,7 +36,7 @@ print (root.filename)
**Python 3 版本:**
```
```py
from tkinter import filedialog
from tkinter import *
......@@ -58,7 +58,7 @@ The `asksaveasfilename` function prompts the user with a save file dialog.
**Python 2.7 版本**
```
```py
from Tkinter import *
import Tkinter, Tkconstants, tkFileDialog
......@@ -70,7 +70,7 @@ print (root.filename)
**Python 3 版本**
```
```py
from tkinter import filedialog
from tkinter import *
......@@ -86,7 +86,7 @@ The `askdirectory` presents the user with a popup for directory selection.
**Python 2.7 版本**
```
```py
from Tkinter import *
import Tkinter, Tkconstants, tkFileDialog
root = Tk()
......
......@@ -12,7 +12,7 @@
The example below creates a Tkinter window with a combobox.
```
```py
from Tkinter import *
import Tkinter as ttk
from ttk import *
......@@ -51,7 +51,7 @@ root.mainloop()
首先创建一个 Tk 对象,并将其传递给使用 Frame()创建的 tkinter 框架
```
```py
root = Tk()
root.title("Tk dropdown example")
mainframe = Frame(root)
......@@ -60,7 +60,7 @@ mainframe = Frame(root)
将一个网格添加到框架,该框架将容纳组合框。
```
```py
mainframe.grid(column=0,row=0, sticky=(N,W,E,S) )
mainframe.columnconfigure(0, weight = 1)
mainframe.rowconfigure(0, weight = 1)
......@@ -70,14 +70,14 @@ mainframe.pack(pady = 100, padx = 100)
弹出菜单包含在变量选项中定义的选项列表。 使用以下行创建一个 Tkinter 变量:
```
```py
tkvar = StringVar(root)
```
变量的默认值是使用.set()方法设置的。 我们使用以下方法创建 Tkinter 组合框:
```
```py
popupMenu = OptionMenu(mainframe, tkvar, *choices)
```
......
......@@ -14,7 +14,7 @@ wxPython 模块基于 C ++ GUI 库 wxWidgets。
To open a window with wxPython, run the code below:
```
```py
#!/usr/bin/python
import wx
......@@ -35,7 +35,7 @@ app.Mainloop()将应用程序置于主循环中并侦听事件。
您可以使用 SetDimensions()函数设置位置和大小:
```
```py
#!/usr/bin/python
import wx
......@@ -54,7 +54,7 @@ app.MainLoop()
要将窗口置于屏幕调用的中心:
```
```py
frame.Centre()
```
\ No newline at end of file
......@@ -8,7 +8,7 @@
您可以使用下面的代码在 [wxPython](https://pythonspot.com/wx/) 中创建一个按钮:
```
```py
#!/usr/bin/python
import wx
......@@ -42,7 +42,7 @@ Buton created with [wxPython](https://pythonspot.com/wx/)
wxPython 支持在按钮上使用图像。 只需稍作更改即可在按钮上显示图像。 虽然该函数称为 wx.BitmapButton,但它支持其他图像格式。
```
```py
bmp = wx.Bitmap("call-start.png", wx.BITMAP_TYPE_ANY)
button = wx.BitmapButton(panel, id=wx.ID_ANY, bitmap=bmp,
size=(bmp.GetWidth()+10, bmp.GetHeight()+10))
......@@ -53,7 +53,7 @@ button = wx.BitmapButton(panel, id=wx.ID_ANY, bitmap=bmp,
完整代码:
```
```py
#!/usr/bin/python
import wx
......
......@@ -8,7 +8,7 @@
信息对话框可以用一行代码显示:
```
```py
import wx
app = wx.App()
......@@ -28,7 +28,7 @@ wx dialog
通过修改参数,您可以轻松创建其他类型的模拟日志。 下面的例子:
```
```py
import wx
app = wx.App()
......@@ -54,7 +54,7 @@ wxDialog
Wx 可用于创建问题对话框(是/否)。 示例代码:
```
```py
import wx
app = wx.App()
......
......@@ -16,7 +16,7 @@
The example below creates a file dialog with a native appearance using wxPython:
```
```py
#!/usr/bin/python
import wx
......@@ -42,7 +42,7 @@ openFileDialog.Destroy()
要使用 [wxPython](https://pythonspot.com/wx/) 创建文件对话框,我们可以简单地调用 wx.FileDialog()。 此方法的定义是:(父,消息,defaultDir,defaultFile,通配符,样式,pos) 我们用以下参数调用此方法:
```
```py
wx.FileDialog(frame, "Open", "", "","Python files (*.py)|*.py",wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
```
......@@ -51,7 +51,7 @@ wx.FileDialog(frame, "Open", "", "","Python files (*.py)|*.py",wx.FD_OPEN | wx.F
showModal()方法显示窗口:
```
```py
openFileDialog.ShowModal()
```
......
......@@ -14,7 +14,7 @@ input dialog made with wxPython
The example code below creates an input dialog with wxPython:
```
```py
#!/usr/bin/python
import wx
......@@ -38,7 +38,7 @@ dlg.Destroy()
可以使用以下函数将 [wxPython](https://pythonspot.com/wx/) 文本框添加到窗口:
```
```py
wx.TextEntryDialog(frame, 'Enter some text','Text Entry')
```
......@@ -47,14 +47,14 @@ wx.TextEntryDialog(frame, 'Enter some text','Text Entry')
下面的函数显示对话框,并等待用户按下按钮之一:
```
```py
dlg.ShowModal()
```
您可以通过选择以下按钮之一来按下按钮:
```
```py
wx.OK
wx.CANCEL
......
......@@ -6,7 +6,7 @@
Mainframe 类创建框架,就像前面的示例一样。 其他类别是选项卡的内容。 我们在主框架中创建一个面板和笔记本(标签夹)。 然后我们创建标签对象:
```
```py
tab1 = TabOne(nb)
tab2 = TabTwo(nb)
...
......@@ -15,7 +15,7 @@ tab2 = TabTwo(nb)
我们使用以下方法将其连接到标签夹:
```
```py
nb.AddPage(tab1, "Tab 1")
nb.AddPage(tab2, "Tab 2")
...
......@@ -24,7 +24,7 @@ nb.AddPage(tab2, "Tab 2")
完整代码:
```
```py
import wx
# Define the tab content as classes:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册