更新python中按钮上的文本

时间:2020-01-21 14:15:59

标签: python tkinter

通过从.txt文档中提取一行,然后将其粘贴到文本位置中,可以访问按钮文本。但是我需要能够点击一下按钮来更新按钮上的文本。问题是它只会给我带来点击次数的更新。 AttributeError: 'NoneType' object has no attribute 'set'

from tkinter.ttk import *
import tkinter

root = tkinter.Tk()
a = 0
with open("Quest.txt") as f:
    lines = f.readlines()
count = len(open("Quest.txt").readlines())

class Main_Frame(tkinter.Frame):
    def __init__(self, parent, *args, **kwargs):
        self.Lab1 = tkinter.Frame.__init__(self, parent, *args, **kwargs)
        global a
        self.But1 = Button(self, text=lines[0], command=self.flip).place(relx=0, rely=0, anchor=NW)

    def flip(self):
        global a
        a = a + 1
        self.But1.set(self, a)

def Run_Main():
    global Main_Frame
    Main_Frame = Main_Frame(root)
    Main_Frame.pack(expand='true', fill='both')
    Main_Frame.configure(background="#3f49e5")
    root.geometry("500x300")

Run_Main()
root.mainloop()```

0 个答案:

没有答案