所以我有一个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循环.
我有两种类型的列表.第一个没有引号,工作和打印平均罚款:
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)
如何计算数字值在引号内的列表?