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

2024-06-16 09:40:01 发布

您现在位置:Python中文网/ 问答频道 /正文

这应该采取一行,并显示在一个文本框,这应该工作,但一定有一个错误,我看不出来。你知道吗

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)

Tags: txteventdatagetifas错误with
1条回答
网友
1楼 · 发布于 2024-06-16 09:40:01

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

相关问题 更多 >