【问题标题】:Python: Spinbox value into function [duplicate]Python:将 Spinbox 值转换为函数 [重复]
【发布时间】:2017-12-13 14:04:12
【问题描述】:

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

#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 的值并将其值引用到函数中,那将非常感谢 :) 非常非常新的编码,如果我的术语有点偏离,非常抱歉。

【问题讨论】:

    标签: python function time tkinter attributeerror


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-11-01
      • 1970-01-01
      • 2019-03-04
      • 2017-07-22
      • 1970-01-01
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 2012-11-24
      相关资源
      最近更新 更多