在没有 ['\n'] 的 Tk 文本框中显示数据

Display data in a Tk text box without the ['\n']

这应该取一行并将其显示在文本框中,这应该可以,但肯定有一个我看不到的错误。

def show_indiv():
    with open("data/tournamentdatae1.txt",'r') as f:
     event = combo_event.get()
     indivcombo = combo_individual.get()  
     if event == 'Event 1' and indivcombo == 'Individual 1': 
           with open('data/tournamentdatae1.txt', 'r') as f:
               for i,line in enumerate(f,1):
                    if i == 21: 
                        indiv_txt.insert(0.0, line)

您不必要地嵌套循环,并三次打开同一个文件。但是你真正的问题是你插入了 get_all;行列表,而不是行。我的建议:

def show_team():    
    if event == 'Event 1': 
        with open('data/tournamentdatae1.txt', 'r') as f: 
            for i, line in enumerate(f, 1):
                if i == 1: 
                    team_1txt.insert(0.0, line)
                elif i == 2: 
                    team_2txt.insert(0.0, line)



team_1txt = Text(root, width=10, height=1)
team_1txt.place(x=100, y=210)

team_2txt = Text(root, width=10, height=1)
team_2txt.place(x=206, y=210)