本文目錄一覽:
- 1、python腳本如何添加啟動和停止按鈕?
- 2、Python中如何實現點擊按鍵A開始循環,點擊按鍵B停止循環?
- 3、python怎麼設置button按鈕
- 4、等一個大佬啊 要求用python創建一個窗口,窗口按鈕功能是創建一個球體或立方體。明天上課之前交給我
python腳本如何添加啟動和停止按鈕?
用tkinter的button組件。
設定好字體大小size(int類型),在循環內部(以while舉例)加組件:
xunhuan=1 # 控制循環的開始與結束
# 定義開始循環
def start():
global xunhuan
xunhuan = 1
# 結束
def end():
global xunhuan
xunhuan = 0
size=(字的大小)
# 現在導庫
inport tkinter as tk # 輸入方便
window = tk.Tk()
s = tk.Button(window, text = “開始” , command = start) # 開始按鈕
e = tk.Button(window , text = “停止” , command = end) # 結束按鈕
# 繪製按鈕
s.pack()
e.pack()
# 下面是循環
while True:
if xunhuan:
…(循環內部要做的事)
window.mainloop() # 在tkinter中,這行代碼一定要加
Python中如何實現點擊按鍵A開始循環,點擊按鍵B停止循環?
1、方法1:while((c=getchar())!=’\n’)
方法2:在循環體中使用if(c==’\n’) break;註:c為輸入的變量
2、例子:
方法1:while((c=getchar())!=’\n’){
//do sth
}
方法2:
for(i=0;i100;i++) {
scanf(“%c”,a[i]);
if(a[i]==’\n’)
break;
}
python怎麼設置button按鈕
生活中我們會遇到各種各樣的登錄界面,比如在登陸QQ時將賬號和密碼輸入完備後,需要點擊“登錄”才能進入到自己的QQ頁面。在Python中,這裡的“登錄”就是用Button組件製作的一個按鈕。
導入tkinter模塊
from tkinter import*
定義函數,用於在shell頁面回答按鈕上面的問題
def answer(): print(“你看我像靚仔嗎?”)
創建根窗口
root=Tk()
創建Button組件
button=Button(root,text=”你是靚仔嗎”,command=answer)#創建變量用於存放Button以及Button中的參數,root為根窗口,text為按鈕上的文本內容,command=answer的作用是將按鈕與函數綁定在一起
在根窗口中展示Button組件
button.pack()
讓根窗口持續展示
root.mainloop()
完整代碼
from tkinter import*def answer(): print(“你看我像靚仔嗎?”)root=Tk()button=Button(root,text=”你是靚仔嗎”,command=answer)button.pack()root.mainloop()
成果展示
使用Python中的Button組件製作按鈕,就分享到這裡!
等一個大佬啊 要求用python創建一個窗口,窗口按鈕功能是創建一個球體或立方體。明天上課之前交給我
下面的代碼是創建一個立方體
”’
This examples creates and displays a simple box.
”’
# The first line loads the init_display function, necessary to
# enable the builtin simple gui provided with pythonocc
from OCC.Display.SimpleGui import init_display
# Then we import the class that instanciates a box
# Here the BRepPrimAPI module means Boundary Representation Primitive API.
# It provides an API for creation of basic geometries like spheres,cones etc
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
# Following line initializes the display
# By default, the init_display function looks for a Qt based Gui (PyQt, PySide)
display, start_display, add_menu, add_function_to_menu = init_display()
# The BRepPrimAPI_MakeBox class is initialized with the 3 parameters of the box: widht, height, depth
my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
# Then the box shape is sent to the renderer
display.DisplayShape(my_box, update=True)
# At last, we enter the gui mainloop
start_display()
創建頁面
#coding:utf8
import wx
app = wx.App() #創建對象
win = wx.Frame(None,title=”ahuang1900″, size=(410,340)) #創建窗口對象
wx.Button(win, label=”open”, pos = (245,5), size=(80,25)) #創建按鈕1
wx.Button(win, label=”save”, pos = (325,5), size=(80,25)) #創建按鈕2
wx.TextCtrl(win, pos=(5,5), size=(240,25)) #創建文本框1
#創建文本框2
wx.TextCtrl(win, pos=(5,35), size=(400,300), style=wx.TE_MULTILINE|wx.HSCROLL)
win.Show() #顯示
app.MainLoop() #主事件循環
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/271770.html