I am trying to get text that a user has inputted and then alternate the case of the text - e.g. If you input 'hello' it will output 'HeLlO'
This is what my Tkinter window looks like
Here is the code I have:
from itertools import cycle
from tkinter import *
win = Tk()
win.title("Alternator")
win.resizable(0,0)
def Alternate():
func = cycle([str.upper, str.lower])
result = ''.join(next(func)(c) for c in entry.get() if c != ' ')
return result
l1 = Label(win, text="Enter text: ")
entry = Text(win, width=50, height = 3, wrap=WORD)
button = Button(win, text="Alternator", width=20)
l2 = Label(win, text="Alternated text:")
output = Text(win, width=50, height=3, wrap=WORD)
l1.grid(row=1, column=1, padx=5, sticky=W)
entry.grid(row=2, column=1, columnspan=2, padx=5, pady=(0,10))
button.grid(row=3, column=1, columnspan=2, pady=5)
l2.grid(row=4, column=1, padx=5, sticky=W)
output.grid(row=5, column=1, columnspan=2, padx=5, pady=(0,10))
button.configure(command=Alternate)
win.mainloop()
What is the correct way to go about this problem? I have seen various questions related, but none that cover this at a basic level