Python:“ NoneType”对象没有属性“ get”

斯特劳

我正在使用tkinter在python中创建GUI,并且在运行它时遇到了麻烦。我有一个输入框小部件,一个单选按钮小部件和一个按钮小部件。当我按下按钮时,我想要的是用户在输入框中键入数字,然后从单选按钮列表中选择一个选项。当用户按下按钮时,我希望检索这些值并将其显示在另一个框架中进行测试。我得到的是,当按下按钮时,出现了错误'NoneType' object has no attribute 'get'错误是指输入框内的值:self.tune_entry

我的代码如下:

SA_main.py

import os
import tkinter as tk
from tkinter import ttk
from tkinter import font
import SA_gui

def main():

    x_vals = [0,1,2,3,4]
    y_vals = [0,1,2,3,4]

    root = SA_gui.tk.Tk()
    UI = SA_gui.Window(root, x_vals, y_vals)

    root.mainloop()


if __name__ == "__main__":
    main()

SA_gui.py

import os
import tkinter as tk
from tkinter import ttk
from tkinter import font

# Class to define, setup, and build the GUI
class Window:

    # Dimensions of the GUI
    HEIGHT = 600
    WIDTH = 1200

    # Colors for main layout
    bg_color = "#B0E0E6"
    frame_color1 = "#73B1B7"
    white_color = "#FFFFFF"

    def __init__(self, master, x_vals, y_vals):

        # Take in the lists of files for later use
        self.x_vals = x_vals
        self.y_vals = y_vals

        #--------------------------------------------------------------

        # Define and create the window
        self.master = master
        master.title("Signal Analysis")
        master.geometry("{}x{}".format(Window.WIDTH, Window.HEIGHT))

        # Create and place the background frame
        self.bg_frame = tk.Frame(self.master, bg=Window.bg_color, bd=5)
        self.bg_frame.place(relwidth=1, relheight=1)

        # Create the main title
        self.main_title = tk.Label(self.bg_frame, text="Software Defined Radio Signal Analysis", 
            bg=Window.bg_color, font=("Courier", 14))
        self.main_title.pack(side="top")

        #--------------------------------------------------------------

        # Create and place the frame for tuning
        self.tune_frame = tk.Frame(self.bg_frame, bg=Window.frame_color1, bd=4)
        self.tune_frame.place(relx=0.05, rely=0.1, relwidth=0.2428, relheight=0.8)

        # Create and place the title for the tuning frame
        self.tune_title = tk.Label(self.tune_frame, text="Tune", bg=Window.frame_color1, font= 
            ("Courier", 11))
        self.tune_title.place(relwidth=1, anchor="nw")

        # Create and place the contents of the tuning frame
        self.tune_cont = tk.Frame(self.tune_frame, bg=Window.white_color, bd=4)
        self.tune_cont.place(relx=0.05, rely=0.05, relwidth=0.9, relheight=0.925)

        #Label for frequency entry
        self.tune_label = tk.Label(self.tune_cont, text='Enter carrier frequency: (kHz)', 
            bg=Window.white_color)
        self.tune_label.place(relx=0.025, rely=0)

        #Entry Box for frequency entry
        self.tune_entry = tk.Entry(self.tune_cont)
        self.tune_entry.place(relx=0.025, rely=0.075, relwidth=0.95, relheight=0.05)

        #Label for divider
        self.tune_div = ttk.Separator(self.tune_cont, orient="horizontal")
        self.tune_div.place(rely=0.175, relwidth=1)

        #Label for display mode
        self.disp_label = tk.Label(self.tune_cont, text='Select Display:', bg=Window.white_color)
        self.disp_label.place(relx=0.025, rely=0.2)

        #Variable for radiobuttons
        self.var = tk.IntVar(self.tune_cont).set("1")

        #Radio Button for Spectral Analysis
        self.SA_select = tk.Radiobutton(self.tune_cont, text="Spectral 
            Analysis",bg=Window.white_color, padx=20, variable=self.var, value=1)
        self.SA_select.place(relx=0.025, rely=0.275)

        #Radio Button for Option 2
        self.opt2_select = tk.Radiobutton(self.tune_cont, text="Option 2",bg=Window.white_color, 
            padx=20, variable=self.var, value=2)
        self.opt2_select.place(relx=0.025, rely=0.35)

        #Radio Button for Option 3
        self.opt3_select = tk.Radiobutton(self.tune_cont, text="Option 3",bg=Window.white_color, 
            padx=20, variable=self.var, value=3)
        self.opt3_select.place(relx=0.025, rely=0.425)


        #Button for selection
        self.tune_button = ttk.Button(self.tune_cont, text="Enter", command=lambda: 
            self.print_selected(self.var.get(), self.tune_entry.get()))
        self.tune_button.place(relx= 0.775, rely=0.9, relwidth=0.2, relheight=0.075)

        #-----------------------------------------------------------------

        # Create and place the frame for the plot
        self.plot_frame = tk.Frame(self.bg_frame, bg=Window.frame_color1, bd=4)
        self.plot_frame.place(relx=0.3428, rely=0.1, relwidth=0.6071, relheight=0.8)

        # Create and place the title for the plot frame
        self.plot_title = tk.Label(self.plot_frame, text="Plot", bg=Window.frame_color1, font= 
            ("Courier", 11))
        self.plot_title.place(relwidth=1, anchor="nw")

        # Create and place the contents of the plot frame
        self.plot_cont = tk.Frame(self.plot_frame, bg=Window.white_color, bd=4)
        self.plot_cont.place(relx=0.025, rely=0.05, relwidth=0.95, relheight=0.925)



    def print_selected(self, disp, freq):
        if disp == 1:
            disp_mode = "Spectral Analysis"
        elif disp == 2:
            disp_mode = "Option 2"
        else:
            disp_mode = "Option 3"

        #Label for this test
        self.prnt_label = tk.Label(self.plot_cont, text="Display: " + disp_mode + ", Center Freq: " + 
            freq, bg=Window.white_color)
        self.prnt_label.place(relx=0.025, rely=0.2)

非常感谢您解决此问题的任何帮助!

布莱恩·奥克利(Bryan Oakley)

考虑以下代码:

self.var = tk.IntVar(self.tune_cont).set("1")

无论何时,x=y().z()python都会将的返回值分配z()x因此,在你的代码你assiging的结果.set("1")self.varset方法返回None这样self.varNone因此,当您稍后尝试调用self.var.get()它时,它与doing相同None.get()

如果要在创建时初始化变量,则无需调用set另外,虽然它可以传递字符串,但是如果您设置了,则IntVar应该将其设置为整数。

self.var = tk.IntVar(value=1)

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

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

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

PYTHON Nonetype 对象没有属性 .get() tkinter

来自分类Dev

AttributeError:'NoneType'对象没有属性'get_text'python网络抓取

来自分类Dev

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

来自分类Dev

'NoneType'对象没有属性'sendall'PYTHON

来自分类Dev

Python'NoneType'对象没有属性'attrs'

来自分类Dev

python'NoneType'对象没有属性'findAll'

来自分类Dev

Python:光标“NoneType”对象没有属性

来自分类Dev

str'对象没有属性'get'python

来自分类Dev

“str”对象没有属性“get”-Python

来自分类Dev

我是python的新手,它是作为个人项目自己尝试的。AttributeError:'NoneType'对象没有属性'get'

来自分类Dev

Praw AttributeError:“ NoneType”对象没有属性“ get_comments”

来自分类Dev

字典:Get():AttributeError:'NoneType'对象没有属性'append'

来自分类Dev

AttributeError:“ NoneType”对象没有属性“ get_default_company”

来自分类Dev

Python suds错误“'NoneType'对象没有属性'promotePrefixes'”

来自分类Dev

Python Flask:AttributeError:'NoneType'对象没有属性'is_active'

来自分类Dev

Python错误:AttributeError:'NoneType'对象没有属性'len'

来自分类Dev

AttributeError:'NoneType'对象没有属性'lower'python

来自分类Dev

Python:AttributeError:'NoneType'对象没有属性'findNext'

来自分类Dev

Fabric / Python:AttributeError:“ NoneType”对象没有属性“ partition”

来自分类Dev

'NoneType'对象没有属性'endswith',django,python

来自分类Dev

Python AttributeError:NoneType对象没有属性“关闭”

来自分类Dev

Python:AttributeError:'NoneType'对象没有属性'groups'

来自分类Dev

'NoneType'对象没有属性'插入'Python列表追加插入

来自分类Dev

AttributeError:'NoneType'对象没有属性'group'无法解析(Python)

来自分类Dev

Python链接列表AttributeError:'NoneType'对象没有属性'next'

来自分类Dev

Python“ AttributeError:'NoneType'对象没有属性”突然出现

来自分类Dev

AttributeError:'NoneType'对象没有属性'save'python-django

来自分类Dev

Python(googletrans)-AttributeError:“ NoneType”对象没有属性“ group”

来自分类Dev

Python:AttributeError:'NoneType'对象没有属性'start'

Related 相关文章

  1. 1

    PYTHON Nonetype 对象没有属性 .get() tkinter

  2. 2

    AttributeError:'NoneType'对象没有属性'get_text'python网络抓取

  3. 3

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

  4. 4

    'NoneType'对象没有属性'sendall'PYTHON

  5. 5

    Python'NoneType'对象没有属性'attrs'

  6. 6

    python'NoneType'对象没有属性'findAll'

  7. 7

    Python:光标“NoneType”对象没有属性

  8. 8

    str'对象没有属性'get'python

  9. 9

    “str”对象没有属性“get”-Python

  10. 10

    我是python的新手,它是作为个人项目自己尝试的。AttributeError:'NoneType'对象没有属性'get'

  11. 11

    Praw AttributeError:“ NoneType”对象没有属性“ get_comments”

  12. 12

    字典:Get():AttributeError:'NoneType'对象没有属性'append'

  13. 13

    AttributeError:“ NoneType”对象没有属性“ get_default_company”

  14. 14

    Python suds错误“'NoneType'对象没有属性'promotePrefixes'”

  15. 15

    Python Flask:AttributeError:'NoneType'对象没有属性'is_active'

  16. 16

    Python错误:AttributeError:'NoneType'对象没有属性'len'

  17. 17

    AttributeError:'NoneType'对象没有属性'lower'python

  18. 18

    Python:AttributeError:'NoneType'对象没有属性'findNext'

  19. 19

    Fabric / Python:AttributeError:“ NoneType”对象没有属性“ partition”

  20. 20

    'NoneType'对象没有属性'endswith',django,python

  21. 21

    Python AttributeError:NoneType对象没有属性“关闭”

  22. 22

    Python:AttributeError:'NoneType'对象没有属性'groups'

  23. 23

    'NoneType'对象没有属性'插入'Python列表追加插入

  24. 24

    AttributeError:'NoneType'对象没有属性'group'无法解析(Python)

  25. 25

    Python链接列表AttributeError:'NoneType'对象没有属性'next'

  26. 26

    Python“ AttributeError:'NoneType'对象没有属性”突然出现

  27. 27

    AttributeError:'NoneType'对象没有属性'save'python-django

  28. 28

    Python(googletrans)-AttributeError:“ NoneType”对象没有属性“ group”

  29. 29

    Python:AttributeError:'NoneType'对象没有属性'start'

热门标签

归档