1

I've been writing this program using the Tkinter module in Python3.6.2. There are buttons to to open a list of teams and a list of competitors and I'd prefer to keep the outputs in one window, however if I click the "Teams" button followed by the "Individuals" button, the two elements open one after the other.

I'm hoping to add a button that resets the window (removing the outputs, leaving just the buttons), but I haven't found any solutions online that work with my program.

from tkinter import *
import tkinter as tk

bgcol = "#0B8CFF"

class MainMenu:
    def __init__(self, master):

        self.master = master
        master.title("Scoring System GUI")
        master.geometry("500x750+75+60")

        self.label = Label(master, text="GUI")
        self.label.pack()

        self.team_button = Button(master, text="Teams", command=self.openTeams)
        self.team_button.pack()

    def openTeams(self):        
        self.label = Label(text="Team #1:")
        self.label.pack()
        team1 = open("team1.csv", "r")
        message = team1.read()
        text = Text(root, width = "50", height = "6", fg = "#000000")
        text.pack()
        text.insert(END, message)
        redteam.close()

Here's a photo of the current output:

Tkinter GUI

Increasingly Idiotic
  • 5,700
  • 5
  • 35
  • 73

2 Answers2

0

You have to clear the Text widget before inserting new strings. Just insert the following line before your text.insert(...) statement:

text.delete('1.0', END)

By the way, if you only want to display a list and not edit it (as I guess is the case here) a Listbox widget if often a better choice than a Text widget.

sciroccorics
  • 2,357
  • 1
  • 8
  • 21
0

To do that you need to create another method inside your class and parse it to another button as callback command.

def reset_func(self):
    self.text.delete('1.0', END)

with this method inside when you parse it as command to your button it will clear the content in text widget .

AD WAN
  • 1,414
  • 2
  • 15
  • 28