Python:将Spinbox值转换为函数

时间:2017-12-13 14:04:12

标签: python function time tkinter attributeerror

所以我已经看过并尝试了几种不同的解决方案,但是我发现没有一种方法可行。到目前为止,我有以下内容:

#Variables
countmin = IntVar()


#Functions

#Used to Determine the customisable counter as well as general time management
#Should be noted 59 seconds is used because function begins counting every second at 00 instead of 01
def timecount(minutes):
    start = time.time()
    time.clock()    
    sec_elapsed = 0
    min_elapsed = 0
    while min_elapsed < minutes:
        sec_elapsed = time.time() - start
        print("minutes count:",min_elapsed,"loop cycle time: %f, seconds count: %02d" % (time.clock() , sec_elapsed)) 
        time.sleep(1)
        if sec_elapsed > 59:
            min_elapsed = +1
            start = time.time()

def startquiz():
    timecount(int(sbcount.get()))

后来我在这里引用它:

sbcount = Spinbox(tab1, from_ = 1, to = 20, textvariable = countmin).pack()
countmin.get()



btquiz = ttk.Button(tab1, text = "Error")
btquiz.config(text = "Begin Quiz", compound = CENTER, command = startquiz)
btquiz.pack()

现在我遇到了以下问题

 File "C:\Users\BugZ\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
    return self.func(*args)
  File "C:\SDD\TKinter Project\Quiz Application.py", line 38, in startquiz
    timecount(int(sbcount.get()))
AttributeError: 'NoneType' object has no attribute 'get'

如果有人可以证明我将如何获得spinbox的价值并将其值引用到函数中它将非常感激:)非常非常新的编码很抱歉如果我的术语有点偏。

1 个答案:

答案 0 :(得分:0)

pack会产生副作用并返回None,也许可以尝试:

sbcount = Spinbox(tab1, from_ = 1, to = 20, textvariable = countmin)
sbcount.pack()