找不到百分比的 AT 内容 (tkinter, 类)

Can't find the AT content in percentage (tkinter, classes)

Python 编程相对较新,并试图让这个程序运行。

tkinter 界面正常启动,一切正常,但一旦我点击计算,它就会在控制台中吐出 A + T 字母的百分比值/您输入的字符串的总长度,但我保留 运行 进入错误。任何帮助将不胜感激。

from tkinter import *


class AT_content_calculator:

    def dna_sequence(self):
        self.dna_sequence = ()

    def __init__(self, master):
        frame_1 = Frame(master, width=700, height=700)
        frame_1.pack()
        frame_1.pack_propagate()

        self.entry_1 = Entry(frame_1, textvariable=self.dna_sequence)
        self.entry_1.pack()
        self.button_1 = Button(frame_1, text="Calculate", command=self.at_calculate)
        self.button_1.pack()
        self.button_2 = Button(frame_1, text="Quit", command=frame_1.quit)
        self.button_2.pack()

    def at_calculate(self):

        self.total_bases = len(self.dna_sequence)
        self.a_bases = self.dna_sequence.count("A")
        self.b_bases = self.dna_sequence.count("T")
        self.at_content = (self.a_bases + self.b_bases) / self.total_bases
        print(self.at_content)

root = Tk()
b = AT_content_calculator(root)
root.mainloop()

添加,self.total_bases = len(self.dna_sequence)

之前的这一行
self.dna_sequence = self.entry_1.get()

你得到:

编辑

尝试:

from tkinter import *

class AT_content_calculator:

    def dna_sequence(self):
        self.dna_sequence = ()

    def __init__(self, master):
        frame_1 = Frame(master, width=700, height=700)
        frame_1.pack()
        frame_1.pack_propagate()
        self.entry_1 = Entry(frame_1)
        self.entry_1.pack()
        self.varoutput_1 = StringVar()
        self.output_1 = Label(frame_1, textvariable=self.varoutput_1)
        self.output_1.pack()
        self.button_1 = Button(frame_1, text="Calculate", command=self.at_calculate)
        self.button_1.pack()
        self.button_2 = Button(frame_1, text="Quit", command=frame_1.quit)
        self.button_2.pack()

    def at_calculate(self):
        self.dna_sequence = self.entry_1.get()
        self.total_bases = len(self.dna_sequence)
        self.a_bases = self.dna_sequence.count("A")
        self.b_bases = self.dna_sequence.count("T")
        self.at_content = (self.a_bases + self.b_bases) / self.total_bases
        print(self.at_content)
        self.varoutput_1.set(self.at_content)

root = Tk()
b = AT_content_calculator(root)
root.mainloop()

你得到: