首页 > 编程知识 正文

python循环创建按钮(python设置按钮)

时间:2023-12-24 12:05:41 阅读:320795 作者:GOWR

本文目录一览:

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()        #主事件循环

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。