Removing curly brackets from a tuple in python
Question: I'm creating a test module to eventually import into a larger program using
python.

My test module uses tkinter widgets to display a list of numbers that
increases when a button is pressed.

    
    
    import tkinter
    import math
    
    #Defining Variables
    
    global Counter
    Counter = 0
    global ArrayDisplay1
    ArrayDisplay1 = Counter
    
    
    #Defining the GUI
    class simpleapp_tk(tkinter.Tk):
        def __init__(self, parent):
            tkinter.Tk.__init__(self, parent)
            self.parent = parent
            self.initialise()
    
        def initialise(self):
    
            #Creating the GUI
    
            self.grid()
            self.resizable(False, False)
    
            self.labelVariableArray3 = tkinter.StringVar()
            ArrayLabel3 = tkinter.Label(self, textvariable=self.labelVariableArray3, anchor='w',bg='white')
            ArrayLabel3.grid(column=2, row=5, columnspan=5, sticky='EW')
            self.labelVariableArray3.set("")
    
            ArrayButton2 = tkinter.Button(self, text=u"Next Number", command=self.ArrayClick2)
            ArrayButton2.grid(column=2, row=3, sticky='EW')
    
    
        def ArrayClick2(self):
            global Counter
            global ArrayDisplay1
            Counter = Counter + 1
            if Counter == 1:
                ArrayDisplay1 = (Counter)
                self.labelVariableArray3.set(ArrayDisplay1)
            else:
                ArrayDisplay1 = (ArrayDisplay1, ",", Counter)
                self.labelVariableArray3.set(ArrayDisplay1)
    
    
    
    
    if __name__ == "__main__":
        app = simpleapp_tk(None)
        app.title('Arrays, Sorts and Searches')
        app.mainloop()
    

my problem lies within the 'ArrayClick2' module. I wrote the code hoping to
have the output be:

1

1, 2

1, 2, 3 and so on. However I instead get:

1

1, 2

{1, 2}, 3

{{1, 2}, 3}, 4 and so forth. I tried using replace and strip, but neither of
these seem to work with a tuple. Can someone tell me of another way to create
this list or just to remove the brackets?

Also I've been told by the head of the program development that I can't use
the python function named list because for some reason that I couldn't
understand it was incompatible with the main program.


Answer: You can concatenate tuples using + for example `tuple0 = tuple0 + (element,)`.

To get your result from tuple you can use join

`''.join(str(element) + ',' for element in ArrayDisplay1)[:-1]`

[:-1] to ignore last element which is `,`

Without changing your code, Changes are:

line 9 : `ArrayDisplay1 = (Counter,)` ArrayDisplay1 must be a tuple

if else statement in ArrayClick2 function:

    
    
    if Counter == 1:
            ArrayDisplay1 = (Counter,)
            self.labelVariableArray3.set(ArrayDisplay1)
    else:
            ArrayDisplay1 +=(Counter,)
            self.labelVariableArray3.set(''.join(str(i)+',' for i in ArrayDisplay1)[:-1])
    

I hope it will be useful.

