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

时间:2018-05-28 10:16:14

标签: python python-3.4 tk

这应该占用一行并将其显示在一个txt框中,这应该可以工作但是必须有一个我看不到的错误。

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)

1 个答案:

答案 0 :(得分:0)

您不必要地嵌套循环,并打开相同的文件三次。但你真正的问题是你插入了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)