AttributeError:'str'对象在tkinter中没有属性'set'

巴斯克维尔先生

我正在尝试使用tkinter在Python中创建和实现一个简单的表单。表单本身是使用PAGE创建的,我现在正在尝试编写代码以与表单进行交互(我仍在学习Python,所以请多多包涵。)

我收到AttributeError:尝试从定义标签的类外部动态设置标签中的文本时,“ str”对象没有属性“ set”。我在网上阅读的所有内容都表明这是达到我想要的结果的方法,但是我为这个错误感到困惑。任何帮助表示赞赏。

该错误发生在setTimerString函数(属于Pulse类的一部分)中。

这是我的主要代码文件:

#! /usr/bin/env python
#
# GUI module generated by PAGE version 4.8.5
# In conjunction with Tcl version 8.6
#    Feb 10, 2017 09:38:24 AM
import sys

try:
    from Tkinter import *
except ImportError:
    from tkinter import *

try:
    import ttk
    py3 = 0
except ImportError:
    import tkinter.ttk as ttk
    py3 = 1

import pulse_support

def vp_start_gui():
    '''Starting point when module is the main routine.'''
    global val, w, root, top
    root = Tk()
    top = Pulse (root)
    pulse_support.init(root, top)
    root.mainloop()

w = None
def create_Pulse(root, *args, **kwargs):
    '''Starting point when module is imported by another program.'''
    global w, w_win, rt
    rt = root
    w = Toplevel (root)
    top = Pulse (w)
    pulse_support.init(w, top, *args, **kwargs)
    return (w, top)

def destroy_Pulse():
    global w
    w.destroy()
    w = None

def startTimer():
    global count
    count = 0 # Reset it evert time the user starts the program
    top.setTimerString("12")


def runProgram():
    # Run the main program
    startTimer()

def closeProgram():
    exit()


class Pulse:
    def __init__(self, top=None):
        '''This class configures and populates the toplevel window.
           top is the toplevel containing window.'''

        self._bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        self._fgcolor = '#000000'  # X11 color: 'black'
        self._compcolor = '#d9d9d9' # X11 color: 'gray85'
        self._ana1color = '#d9d9d9' # X11 color: 'gray85' 
        self._ana2color = '#d9d9d9' # X11 color: 'gray85' 

        top.geometry("320x344+599+249")
        top.title("Pulse")
        top.configure(background="#d9d9d9")

        # Set the strings to use for the form
        self.countString = StringVar()
        self.timerString = StringVar()
        self.countString = "0"
        self.timerString = "0"

        self.btnExit = Button(top)
        self.btnExit.place(relx=0.84, rely=0.03, height=24, width=39)
        self.btnExit.configure(activebackground="#d9d9d9")
        self.btnExit.configure(activeforeground="#000000")
        self.btnExit.configure(background="#d9d9d9")
        self.btnExit.configure(command=closeProgram)
        self.btnExit.configure(disabledforeground="#a3a3a3")
        self.btnExit.configure(foreground="#000000")
        self.btnExit.configure(highlightbackground="#d9d9d9")
        self.btnExit.configure(highlightcolor="black")
        self.btnExit.configure(pady="0")
        self.btnExit.configure(text='''Exit''')
        self.btnExit.configure(width=39)

        self.btnStart = Button(top)
        self.btnStart.place(relx=0.31, rely=0.17, height=104, width=125)
        self.btnStart.configure(activebackground="#d9d9d9")
        self.btnStart.configure(activeforeground="#000000")
        self.btnStart.configure(background="#d9d9d9")
        self.btnStart.configure(command=runProgram)
        self.btnStart.configure(disabledforeground="#a3a3a3")
        self.btnStart.configure(foreground="#000000")
        self.btnStart.configure(highlightbackground="#d9d9d9")
        self.btnStart.configure(highlightcolor="black")
        self.btnStart.configure(pady="0")
        self.btnStart.configure(text='''Start''')
        self.btnStart.configure(width=125)

        self.Label1 = Label(top)
        self.Label1.place(relx=0.31, rely=0.58, height=21, width=54)
        self.Label1.configure(background="#d9d9d9")
        self.Label1.configure(disabledforeground="#a3a3a3")
        self.Label1.configure(foreground="#000000")
        self.Label1.configure(text='''Timer:''')
        self.Label1.configure(width=54)

        self.lblTimer = Label(top)
        self.lblTimer.place(relx=0.5, rely=0.58, height=21, width=32)
        self.lblTimer.configure(background="#a8aeff")
        self.lblTimer.configure(disabledforeground="#a3a3a3")
        self.lblTimer.configure(foreground="#000000")
        self.lblTimer.configure(textvariable=self.countString)
        self.lblTimer.configure(width=32)

        self.Label3 = Label(top)
        self.Label3.place(relx=0.33, rely=0.67, height=21, width=43)
        self.Label3.configure(background="#d9d9d9")
        self.Label3.configure(disabledforeground="#a3a3a3")
        self.Label3.configure(foreground="#000000")
        self.Label3.configure(text='''Count:''')

        self.lblCount = Label(top)
        self.lblCount.place(relx=0.5, rely=0.67, height=21, width=32)
        self.lblCount.configure(activebackground="#f9f9f9")
        self.lblCount.configure(activeforeground="black")
        self.lblCount.configure(background="#ffa8a8")
        self.lblCount.configure(disabledforeground="#a3a3a3")
        self.lblCount.configure(foreground="#000000")
        self.lblCount.configure(highlightbackground="#d9d9d9")
        self.lblCount.configure(highlightcolor="black")
        self.lblCount.configure(textvariable=self.countString)

        self.Label4 = Label(top)
        self.Label4.place(relx=0.13, rely=0.84, height=36, width=237)
        self.Label4.configure(background="#d9d9d9")
        self.Label4.configure(disabledforeground="#a3a3a3")
        self.Label4.configure(foreground="#000000")
        self.Label4.configure(text='''Press the start button to start the program.
Every time your pulse beats, press the P key.''')

    def setTimerString(self, newVal):
        self.timerString.set(newVal)


if __name__ == '__main__':
    vp_start_gui()
保罗·鲁尼
self.countString = StringVar()
self.countString = "0"

将扔掉StringVar并将其替换为常规的str,即没有set方法的那种

反而

self.countString.set("0")

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

AttributeError:“ str”对象没有属性“ toLowerCase”

来自分类Dev

AttributeError:'str'对象没有属性'get'

来自分类Dev

AttributeError:“ str”对象没有属性“ items”

来自分类Dev

AttributeError:'str'对象没有属性'sleep'

来自分类Dev

AttributeError:“ str”对象没有属性“ maketrans”

来自分类Dev

AttributeError:'str'对象没有属性(功能)

来自分类Dev

attributeError:'str'对象没有属性'dbname'

来自分类Dev

AttributeError:“ str”对象没有属性“ values”

来自分类Dev

AttributeError:'str'对象没有属性'description'

来自分类Dev

AttributeError:'str'对象没有属性'union'

来自分类Dev

AttributeError:“ str”对象没有属性“ float”

来自分类Dev

AttributeError'str'对象没有属性'path'

来自分类Dev

AttributeError:'str'对象没有属性

来自分类Dev

AttributeError:“ str”对象没有属性“ name”

来自分类Dev

AttributeError: 'str' 对象没有属性 'keys'

来自分类Dev

AttributeError: 'str' 对象没有属性 'loc'

来自分类Dev

AttributeError: 'str' 对象没有属性 'channel'

来自分类Dev

AttributeError: 'str' 对象没有属性 'mode'

来自分类Dev

AttributeError: 'str' 对象没有属性 'map'

来自分类Dev

AttributeError: 'str' 对象没有属性 'execute'

来自分类Dev

AttributeError: 'str' 对象没有属性 'client'

来自分类Dev

Python 3.4:str:AttributeError:'str'对象没有属性'decode

来自分类Dev

Python 3.4:str:AttributeError:'str'对象没有属性'decode

来自分类Dev

/ posts / create /中的AttributeError:尝试解析标题字段中的主题标签并将其保存在标签字段中时,“ str”对象没有属性“ set”

来自分类Dev

包含 Pandas 数据框列中的函数(AttributeError: 'str' 对象没有属性 'str'

来自分类Dev

Django makemigrations AttributeError:“ str”对象没有属性“ _meta”

来自分类Dev

Python-AttributeError:“ str”对象没有属性“ isDigit”

来自分类Dev

Django 1.8:/:“ str”对象上的AttributeError没有属性“ copy”

来自分类Dev

如何修复AttributeError:'str'对象没有属性'_radius'?

Related 相关文章

  1. 1

    AttributeError:“ str”对象没有属性“ toLowerCase”

  2. 2

    AttributeError:'str'对象没有属性'get'

  3. 3

    AttributeError:“ str”对象没有属性“ items”

  4. 4

    AttributeError:'str'对象没有属性'sleep'

  5. 5

    AttributeError:“ str”对象没有属性“ maketrans”

  6. 6

    AttributeError:'str'对象没有属性(功能)

  7. 7

    attributeError:'str'对象没有属性'dbname'

  8. 8

    AttributeError:“ str”对象没有属性“ values”

  9. 9

    AttributeError:'str'对象没有属性'description'

  10. 10

    AttributeError:'str'对象没有属性'union'

  11. 11

    AttributeError:“ str”对象没有属性“ float”

  12. 12

    AttributeError'str'对象没有属性'path'

  13. 13

    AttributeError:'str'对象没有属性

  14. 14

    AttributeError:“ str”对象没有属性“ name”

  15. 15

    AttributeError: 'str' 对象没有属性 'keys'

  16. 16

    AttributeError: 'str' 对象没有属性 'loc'

  17. 17

    AttributeError: 'str' 对象没有属性 'channel'

  18. 18

    AttributeError: 'str' 对象没有属性 'mode'

  19. 19

    AttributeError: 'str' 对象没有属性 'map'

  20. 20

    AttributeError: 'str' 对象没有属性 'execute'

  21. 21

    AttributeError: 'str' 对象没有属性 'client'

  22. 22

    Python 3.4:str:AttributeError:'str'对象没有属性'decode

  23. 23

    Python 3.4:str:AttributeError:'str'对象没有属性'decode

  24. 24

    / posts / create /中的AttributeError:尝试解析标题字段中的主题标签并将其保存在标签字段中时,“ str”对象没有属性“ set”

  25. 25

    包含 Pandas 数据框列中的函数(AttributeError: 'str' 对象没有属性 'str'

  26. 26

    Django makemigrations AttributeError:“ str”对象没有属性“ _meta”

  27. 27

    Python-AttributeError:“ str”对象没有属性“ isDigit”

  28. 28

    Django 1.8:/:“ str”对象上的AttributeError没有属性“ copy”

  29. 29

    如何修复AttributeError:'str'对象没有属性'_radius'?

热门标签

归档