小编Jon*_*ies的帖子

如何创建Tkinter GUI停止按钮以打破无限循环?

所以我有一个Tkinter GUI,有两个简单的选项,一个启动和停止按钮.我已经定义了GUI布局:

from Tkinter import *

def scanning():
    while True:
        print "hello"

root = Tk()
root.title("Title")
root.geometry("500x500")

app = Frame(root)
app.grid()
Run Code Online (Sandbox Code Playgroud)

这里的"开始"按钮运行无限循环扫描,按下"停止"按钮应按下:

start = Button(app, text="Start Scan",command=scanning)
stop = Button(app, text="Stop",command="break")

start.grid()
stop.grid()
Run Code Online (Sandbox Code Playgroud)

但是,当我点击"开始"按钮时,它总是被按下(假设是因为无限循环).但是,我无法单击"停止"按钮以突破while循环.

python user-interface tkinter

5
推荐指数
2
解决办法
3万
查看次数

你如何在python中找到带引号的数字列表的平均值?

我有两种类型的列表.第一个没有引号,工作和打印平均罚款:

l = [15,18,20]
print l
print "Average: ", sum(l)/len(l)
Run Code Online (Sandbox Code Playgroud)

这打印:

[15,18,20]
Average: 17
Run Code Online (Sandbox Code Playgroud)

第二个列表包含引号的数字,返回错误:

x = ["15","18","20"]
print x
print "Average: ", sum(x)/len(x)
Run Code Online (Sandbox Code Playgroud)

错误是:

TypeError: unsupported operand type(s) for +: 'int' and 'str'
Run Code Online (Sandbox Code Playgroud)

如何计算数字值在引号内的列表?

python unix linux

3
推荐指数
1
解决办法
129
查看次数

标签 统计

python ×2

linux ×1

tkinter ×1

unix ×1

user-interface ×1