So I am trying to have a GUI for my Converter (it is intentionally meant to go up to 255 aka 8bits)
And I have got it to work on the button layout as planned. But to make it more user-friendly I wanted to put a 'Convert From' label/text above the buttons. However, as soon as I shifted the buttons down a row it didn't go as planned and after careful examination of it. I have got nowhere.
image reference of how it looks without label above the buttons (row = 0)
image reference of how it looks with the label above the buttons
as you can see it takes it off screen and out of uniform (row = 1)
#Converter GUI
#importing necessary libaries
import tkinter
import tkinter.ttk
import tkinter.messagebox
import sys
#defining the types of conversion
def bin2den(value):
if len(value) != 8: #checks that it has a length of 8 binary digits
return "None"
return int(value, 2)
def bin2hex(value):
if len(value) != 8: #checks that it has a length of 8 binary digits
return "None"
Ox = hex(int(value, 2))[2:].upper()
Ox = Ox.zfill(2)
return Ox
def bin2bin(value):
if len(value) != 8: #checks that it has a length of 8 binary digits
print("Invalid input, 8 bits required!")
return "None"
return value.zfill(8)
def den2bin(value):
if int(value) > 255 or int(value) < 0:
return "None"
Ob = bin(int(value))[2:]#removing the ob prefix
filled = Ob.zfill(8) #filling it to become an 8 bit binary if worth less than 8 bits
return filled
def den2hex(value):
if int(value) > 255 or int(value) < 0:
return "None"
Ox = hex(int(value))[2:].upper() #removing the ox prefix and capitalising the hex output
Ox = Ox.zfill(2)#filling the output if not double digits
return Ox
def den2den(value):
if int(value) > 255 or int(value) < 0:
print("Out Of Range")
return "None"
return value
def hex2bin(value):
while len(value) != 2 and len(value) > 2: #checking if hex value outside of ff
return "None"
Ob = bin(int(value, 16))[2:] #removing the ob prefix
Ob = Ob.zfill(8)#filling binary to be 8bits if value is below 8 bits
return Ob
def hex2den(value):
while len(value) != 2 and len(value) > 2: #checking if hex value outside of ff
return "None"
return int(value, 16)
def hex2hex(value):
while len(value) != 2 and len(value) > 2: #checking if hex value outside of ff
print("Invalid input, try again")
return "None"
value = value.upper() #capitaliseing for formality
return value
def readFile(fileName):
fileObj = open(fileName, "r")#opens file in read only mode
HexArray = fileObj.read().splitlines()#puts file into an array
fileObj.close()
return HexArray
#setting main window class
#and defining main attributes of the window
class MainWindow():
FONT = ("Consolas", 16)
TxtMaxLen = 32
def __init__(self):
self._window = tkinter.Tk()
self._window.title("Converter")
#self._window.geometry("800x240") redundant as set below due to positioning
self._window["bg"] = "#20A3FF" #background colour
self._window.resizable(False, False) #stops the window being resized
windowWidth = self._window.winfo_reqwidth()
windowHeight = self._window.winfo_reqheight()
# Gets both half the screen width/height and window width/height
positionRight = int(self._window.winfo_screenwidth()/2 - windowWidth/2)-330
positionDown = int(self._window.winfo_screenheight()/2 - windowHeight/2)-200
self._window.geometry(f"{windowWidth}x{windowHeight}+{positionRight}+{positionDown}")
self._window.geometry("800x240")#setting window size
label = tkinter.Label(self._window, text="Number: ", font=MainWindow.FONT)#label defined for number input box
label.grid(row=0, column=0, padx=10, pady=5)#positioning / dimensions of input box
self._txt_input = tkinter.Entry(self._window, width=MainWindow.TxtMaxLen, font=MainWindow.FONT) #defined input box
self._txt_input.grid(row=0, column=1, pady=5)#postioning / dimensions of input box
self._txt_input.focus()
#this is the label that is just runining it
#label = tkinter.Label(self._window, text="Convert From ", font=MainWindow.FONT)
#label.grid(row=0, column=2, padx=5, pady=5)#positioning / dimensions of input box
#following 6 bits of code when row = 0 it works fine but when shifted down a row it goes wrong
self._bt_bin = tkinter.Button(self._window, text="Bin", font=MainWindow.FONT, command=self.BinSelection)#button defined for bin
self._bt_bin.grid(row=0, column=2, padx=5, pady=5)#postioning / dimensions of button box
self._bt_den = tkinter.Button(self._window, text="Den", font=MainWindow.FONT, command=self.DenSelection)#button defined for den
self._bt_den.grid(row=0, column=4, padx=5, pady=5)#postioning / dimensions of button box
self._bt_hex = tkinter.Button(self._window, text="Hex", font=MainWindow.FONT, command=self.HexSelection)#button defined for bin
self._bt_hex.grid(row=0, column=6, padx=5, pady=5)#postioning / dimensions of button box
separator = tkinter.ttk.Separator(self._window,orient=tkinter.HORIZONTAL)
separator.grid(row=1, column=1, pady=4)
#setting the Output boxes and the labels accordingly
#binary output box and label
label = tkinter.Label(self._window, text="Binary:", font=MainWindow.FONT)#label defined for number box
label.grid(row=2, column=0, padx=10, pady=5)
self._stringvar_bin = tkinter.StringVar()
txt_output = tkinter.Entry(self._window, textvariable=self._stringvar_bin, width=MainWindow.TxtMaxLen, state="readonly", font=MainWindow.FONT)#entry box set to readonly to act as a display box
txt_output.grid(row=2, column=1, pady=5)
#denary output box and label
label = tkinter.Label(self._window, text="Denary:", font=MainWindow.FONT)#label defined for number box
label.grid(row=3, column=0, padx=5, pady=5)
self._stringvar_den = tkinter.StringVar()
txt_output = tkinter.Entry(self._window, textvariable=self._stringvar_den, width=MainWindow.TxtMaxLen, state="readonly", font=MainWindow.FONT)
txt_output.grid(row=3, column=1, pady=5)
#hexadecimal output box and label
label = tkinter.Label(self._window, text="Hexadecimal:", font=MainWindow.FONT)#label defined for number box
label.grid(row=4, column=0, padx=5, pady=5)
self._stringvar_hex = tkinter.StringVar()
txt_output = tkinter.Entry(self._window, textvariable=self._stringvar_hex, width=MainWindow.TxtMaxLen, state="readonly", font=MainWindow.FONT)
txt_output.grid(row=4, column=1, pady=5)
def BinSelection(self):
try:
Bin = self._txt_input.get().strip().replace(" ", "")
BinValue = bin2bin(Bin)
DenValue = bin2den(Bin)
HexValue = bin2hex(Bin)
self._set_values(BinValue, DenValue, HexValue)
except Exception as ex:
tkinter.messagebox.showerror("Error", "Invalid conversion")
tkinter.messagebox.showinfo("Error", "Enter a valid 8 bit binary number or a integer / hexadecimal value")
print(ex, file=sys.stderr)
def DenSelection(self):
try:
Den = self._txt_input.get().strip().replace(" ", "")
DenValue = den2den(Den)
BinValue = den2bin(Den)
HexValue = den2hex(Den)
self._set_values(BinValue, DenValue, HexValue)
except Exception as ex:
tkinter.messagebox.showerror("Error", "Invalid conversion")
print(ex, file=sys.stderr)
def HexSelection(self):
try:
Hex = self._txt_input.get().strip().replace(" ", "")
HexValue = hex2hex(Hex)
BinValue = hex2bin(Hex)
DenValue = hex2den(Hex)
self._set_values(BinValue, DenValue, HexValue)
except Exception as ex:
tkinter.messagebox.showerror("Error", "Invalid conversion")
print(ex, file=sys.stderr)
def _set_values(self, BinValue, DenValue, HexValue):
if not BinValue.startswith(""):
BinValue = "" + BinValue
if not HexValue.startswith(""):
HexValue = "" + HexValue
self._stringvar_bin.set(BinValue)
self._stringvar_den.set(DenValue)
self._stringvar_hex.set(HexValue)
def mainloop(self):
self._window.mainloop()
if __name__ == "__main__":
win = MainWindow()
win.mainloop()
any insight on how to fix this would be great thanks. and sorry if this whole question was just a silly one.
Answer to my question as the Issue is now resolved. Fixed it using columnspan which allows you to set a box across several columns.
label = tkinter.Label(self._window, text="Convert From ", font=MainWindow.FONT)
label.grid(row=0, column=2,columnspan=3, padx=5, pady=5)
Here is what it looks like with the resolved problem
Related
The main function gives me an error, not sure how I can fix this, and some explanation as to what is happening in this error will be much appreciated.
I tried to input in the entry field a random position in this format "28.834592° -46.099829°" without quotes.
import tkinter as tk
import ctypes
window = tk.Tk()
user32 = ctypes.windll.user32
# Main Function
def main():
lat = input_coordinate()[0]
long = input_coordinate()[1]
print(lat,long)
def input_coordinate():
try:
user_coordinates = lat_long_Entry.get()
# print (user_coordinates)
new_user_coordinates = user_coordinates.replace("°"," ")
new_coordinates = new_user_coordinates.split(" ",1)
#print (new_user_coordinates)
coordinates = []
counter = []
for item in new_coordinates:
coordinates.append(float(item))
#print (coordinates)
for i in range(len(coordinates)):
counter.append(i)
#print (counter)
if (coordinates[0] is str) or (counter[0] is None) or (counter == [0]):
print("fail")
else:
print("Success")
return coordinates
except ValueError:
popupmsg_nocoordinate()
def popupmsg_nocoordinate():
popup = tk.Tk()
popup.wm_title("Error")
label = tk.Label(popup, text="Please Enter a Valid Coordinates in decimal degree !", font="NORM_FONT")
label.pack(side="top", fill="x", pady=10)
B4 = tk.Button(popup, text="Cancel", command=popup.destroy)
B4.pack()
popup.mainloop()
# label fields
window.title("Scale Calculator")
window.geometry('350x350')
Title = tk.Label(text="Calculator")
lat_long = tk.Label(text="Enter Coordinates")
lat_long_Entry = tk.Entry()
run = tk.Button(text="Run", command=main)
lat_long.grid (row=1, column=0, )
lat_long_Entry.grid (row=1, column=2, )
run.grid (row=5, column=0, )
window.mainloop()
I feel this is not the most optimized way to achieve what I wanted.
I'm trying to create a factorial calculator GUI.
The program works fine, but the problem I'm having is that when there are too many numbers coming in from the output, the screen automatically increases in width. I've tried using tk.Text to create a limit to the size of the textbox and so the text continues to the next row when the columns are filled.
But when I had to input text in to the tk.Text it didn't work since the variable I used is being processed in the function that gets called when the button is pressed. I have tried googling this problem but I couldn't find anything, I did find some people explaining how to use variables that get created/processed inside of a function, but that didn't work so I think I have done something wrong in my code.
Note: I am using lambda to call my function (not sure if this is important or not).
TLDR: Text gets too long when too much information is outputted. tk.Text didn't work for me since I couldn't figure out how to use the variable that is created/processed inside of a function that is only called when the button is pressed.
Here is my entire code: https://pastebin.com/1MkdRjVE
Code for my function:
def start_calc():
output_array = ["placehold"]
start_text.set("Loading...")
i = 1
global e1
global e2
output_array.clear()
string = e1.get()
string2 = e2.get()
integr = int(string)
integr2 = int(string2)
if string == "":
error_message.set("Please enter correct numbers.")
elif string2 == "":
error_message.set("Please enter correct numbers.")
else:
while integr2 >= i:
calc = integr ** i
calcstr = (str(calc))
output_array.append(calcstr)
i += 1
start_text.set("Start!")
output_array_str = (', '.join(output_array))
output_msg.set("Output: " + output_array_str)
print(output_array_str) #This is just so I know if it's working or not in the terminal
Code for my output:
output_msg = tk.StringVar()
output_text = tk.Label(root, textvariable=output_msg, font="Raleway")
output_msg.set("Output: ")
output_text.grid(columnspan=3, column=0, row=14)
I think this is what you are looking for:
#Imports
import tkinter as tk
#Variables
root = tk.Tk()
#Tkinter GUI setup basic
canvas = tk.Canvas(root, width= 400, height=400)
canvas.grid(columnspan=3, rowspan=120)
#Title
text = tk.Label(root, text="Calculating factorials", font="Raleway")
text.grid(column=1, row=1)
#Function
def start_calc():
output_array = ["", ""]
start_text.set("Loading...")
i = 1
global e1
global e2
output_array.clear()
string = e1.get()
string2 = e2.get()
integr = int(string)
integr2 = int(string2)
if string == "":
error_message.set("Please enter correct numbers.")
elif string2 == "":
error_message.set("Please enter correct numbers.")
else:
while integr2 >= i:
calc = integr ** i
calcstr = (str(calc))
output_array.append(calcstr)
i += 1
start_text.set("Start!")
output_array_str = (', '.join(output_array))
# Change the output
output_text.config(state="normal")
# delete last output:
output_text.delete("0.0", "end")
# insert new output:
output_text.insert("end", output_array_str)
output_text.config(state="disabled")
print(output_array_str) #This is just so I know if it's working or not in the terminal
#input
tk.Label(root, text="Number :").grid(row=10)
tk.Label(root, text="Factorial :").grid(row=11)
e1 = tk.Entry(root)
e2 = tk.Entry(root)
e1.grid(row=10, column=1)
e2.grid(row=11, column=1)
#Error message if the input is invalid
error_message = tk.StringVar()
error_text = tk.Label(root, textvariable=error_message, font="Raleway")
error_message.set(" ")
error_text.grid(column=1, row=12)
#Startbutton
start_text = tk.StringVar()
start_btn = tk.Button(root, textvariable=start_text, command=start_calc, font="Raleway", bg="#20bebe", fg="white", height=2, width=15)
start_text.set("Start!")
start_btn.grid(column=1, row=13, pady=10)
#output
output_text = tk.Text(root, height=1, width=20, wrap="none", font="Raleway")
output_text.insert("end", "Output")
output_text.config(state="disabled")
output_text.grid(columnspan=3, column=0, row=14, sticky="news")
#Adding a scrollbar
scrollbar = tk.Scrollbar(root, orient="horizontal", command=output_text.xview)
scrollbar.grid(columnspan=3, column=0, row=15, sticky="news")
output_text.config(xscrollcommand=scrollbar.set)
#disclaimer message
disclaimer_text = tk.Label(root, text="Disclaimer: The factorials will be printed from 1 to the number you entered.")
disclaimer_text.grid(columnspan=3, column=0, row=110)
root.mainloop()
I used a <tkinter.Text> widget with wrap="none", height=1 and width=20 to make the output box. I disabled the entry so that the user can't change the results but can still copy it.
The entry widget in my programme for numbers is working correctly to only allow a maximum of 3 numbers while I tried to do the same thing in a different entry widget but for characters the limit isn't working, I've got no clue why. Do you have to it in a different way since you're using letters?
Here is my code:
def only_letters_max_86(action, char):
if action == "1":
# a character is inserted (deletion is 0) allow the insertion
# only if the inserted character char is a letter
return char.isalpha() and len(char) <= 86
else:
# allow deletion
return True
def only_numbers_max_3(action, new_text):
if action == "1":
return new_text.isdigit() and len(new_text) <= 3
else:
return True
def main():
validate_letter = window.register(only_letters_max_86)
validate_nb = window.register(only_numbers_max_3)
label = Label(window, width = 30, background = 'lightgreen', text='enter temperature, only numbers')
label.grid(row=0, column=0)
entry_tempp = Entry(window, width = 30, validate="key", validatecommand=(validate_nb, '%d', '%P'))
entry_tempp.grid(row = 0, column = 1)
#create another label and entry object for location
label_numb = Label(window, width = 30, background = 'lightgreen', text='enter location, only letters')
label_numb.grid(row=1, column=0)
entry_locations = Entry(window, width = 30, validate="key", validatecommand=(validate_letter, '%d', '%S', '%v'))
entry_locations.grid(row = 1, column = 1)
On this line:
entry_locations = Entry(window, width = 30, validate="key", validatecommand=(validate_letter, '%d', '%S', '%v'))
You are passing '%S' to your validate_letter function which looking at the docs means:
'%S': If the call was due to an insertion or deletion, this argument will be the text being inserted or deleted.
So my guess is that char in only_letters_max_86(action, char) only gets the character that is being inserted which will always be of length one, causing your check to fail. Try changing %S to %Pwhich gives you:
'%P': The value that the text will have if the change is allowed.
Link to the docs: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/entry-validation.html
I am trying to make a 'guess the number' game with Pyhon tkinter but so far I have not been able to retrieve the input from the user.
How can I get the input in entry when b1 is pressed?
I also want to display a lower or higher message as a clue to the player but I am not sure if what I have is right:
import time
import random
import decimal
import tkinter as tk
root = tk.Tk()
randomnum = float(decimal.Decimal(random.randrange(100,10000))/100)
guess = 0
def get(entry):
guess = entry.get()
return guess
def main():
b1 = tk.Button(root, text="Guess", command=get)
entry = tk.Entry()
b1.grid(column=1, row=0)
entry.grid(column=0, row=0)
root.mainloop()
print(guess)
if guess < randomnum:
l2 = tk.Label(root, text="Higher!")
l2.grid(column=0, row=2)
elif guess > randomnum:
l3 = tk.Label(root, text="Lower!")
l3.grid(column=0, row=2)
while guess != randomnum:
main()
l4 = tk.Label(root, text="Well guessed")
time.sleep(10)
You could define get inside main, so that you can access the entry widget you created beforehand, like this:
entry = tk.Entry()
def get():
guess = entry.get()
return guess # Replace this with the actual processing.
b1 = tk.Button(root, text="Guess", command=get)
You've assembled random lines of code out of order. For example, the root.mainloop() should only be called once after setting up the code but you're calling it in the middle of main() such that anything after won't execute until Tk is torn down. And the while guess != randomnum: loop has no place in event-driven code. And this, whatever it is, really should be preceded by a comment:
randomnum = float(decimal.Decimal(random.randrange(100,10000))/100)
Let's take a simpler, cleaner approach. Rather than holding onto pointers to the the various widgets, let's use their textvariable and command properties to run the show and ignore the widgets once setup. We'll use StringVar and IntVar to handle input and output. And instead of using sleep() which throws off our events, we'll use the after() feature:
import tkinter as tk
from random import randint
def get():
number = guess.get()
if number < random_number:
hint.set("Higher!")
root.after(1000, clear_hint)
elif number > random_number:
hint.set("Lower!")
root.after(1000, clear_hint)
else:
hint.set("Well guessed!")
root.after(5000, setup)
def setup():
global random_number
random_number = randint(1, 100)
guess.set(0)
hint.set("Start Guessing!")
root.after(2000, clear_hint)
def clear_hint():
hint.set("")
root = tk.Tk()
hint = tk.StringVar()
guess = tk.IntVar()
random_number = 0
tk.Entry(textvariable=guess).grid(column=0, row=0)
tk.Button(root, text="Guess", command=get).grid(column=1, row=0)
tk.Label(root, textvariable=hint).grid(column=0, row=1)
setup()
root.mainloop()
Here is a tkinter version on the number guessing game.
while or after are not used!
Program checks for illegal input (empty str or words) and reports error message. It also keeps track of the number of tries required to guess the number and reports success with a big red banner.
I've given more meaningful names to widgets and used pack manager instead of grid.
You can use the button to enter your guess or simply press Return key.
import time
import random
import tkinter as tk
root = tk.Tk()
root.title( "The Number Guessing Game" )
count = guess = 0
label = tk.Label(root, text = "The Number Guessing Game", font = "Helvetica 20 italic")
label.pack(fill = tk.BOTH, expand = True)
def pick_number():
global randomnum
label.config( text = "I am tkinking of a Number", fg = "black" )
randomnum = random.choice( range( 10000 ) )/100
entry.focus_force()
def main_game(guess):
global count
count = count + 1
entry.delete("0", "end")
if guess < randomnum:
label[ "text" ] = "Higher!"
elif guess > randomnum:
label[ "text" ] = "Lower!"
else:
label.config( text = f"CORRECT! You got it in {count} tries", fg = "red" )
root.update()
time.sleep( 4 )
pick_number()
count = 0
def get( ev = None ):
guess = entry.get()
if len( guess ) > 0 and guess.lower() == guess.upper():
guess = float( guess )
main_game( guess )
else:
label[ "text" ] = "MUST be A NUMBER"
entry.delete("0", "end")
entry = tk.Entry(root, font = "Helvetica 15 normal")
entry.pack(fill = tk.BOTH, expand = True)
entry.bind("<Return>", get)
b1 = tk.Button(root, text = "Guess", command = get)
b1.pack(fill = tk.BOTH, expand = True)
pick_number()
root.geometry( "470x110" )
root.minsize( 470, 110 )
root.mainloop()
Correct way to write guess number.
I write a small script for number guessing game in Python in
get_number() function.
Used one widget to update Label instead of duplicating.
I added some extra for number of turns that you entered.
Code modified:
import time
import random
import decimal
import tkinter as tk
root = tk.Tk()
randomnum = float(decimal.Decimal(random.randrange(100,10000))/100)
print(randomnum)
WIN = False
GUESS = 0
TURNS = 0
Vars = tk.StringVar(root)
def get_number():
global TURNS
while WIN == False:
Your_guess = entry.get()
if randomnum == float(Your_guess):
guess_message = f"You won!"
l3.configure(text=guess_message)
number_of_turns = f"Number of turns you have used: {TURNS}"
l4.configure(text=number_of_turns)
l4.grid(column=0, row=3, columnspan=3, pady=5)
WIN == True
break
else:
if randomnum > float(Your_guess):
guess_message = f"Your Guess was low, Please enter a higher number"
else:
guess_message = f"your guess was high, please enter a lower number"
l3.configure(text=guess_message)
l3.grid(column=0, row=2, columnspan=3, pady=5)
TURNS +=1
return Your_guess
label = tk.Label(root, text="The Number Guessing Game", font="Helvetica 12 italic")
label.grid(column=0, row=0, columnspan=3, sticky='we')
l2 = tk.Label(root, text='Enter a number between 1 and 100',
fg='white', bg='blue')
l2.grid(row=1, column=0, sticky='we')
entry = tk.Entry(root, width=10, textvariable=Vars)
entry.grid(column=1, row=1, padx=5,sticky='w')
b1 = tk.Button(root, text="Guess", command=get_number)
b1.grid(column=1, row=1, sticky='e', padx=75)
l3 = tk.Label(root, width=40, fg='white', bg='red' )
l4 = tk.Label(root, width=40, fg='white', bg='black' )
root.mainloop()
while guess:
time.sleep(10)
Output for enter floating numbers:
Output after the guess was high:
Output after the guess was low:
Output You won and number of turns:
When I run this no errors come up, but the button does not return anything
import tkinter
#imports the tkinter module
window = tkinter.Tk()
#creates window
window.geometry("675x300")
#sets window size
window.configure(background="#66FFFF")
#sets window background
window.title("Vigenere Cipher")
#Window title
window.wm_iconbitmap('favicon.ico')
#window logo
photo = tkinter.PhotoImage(file="vigciph12.gif")
#imports photo
w = tkinter.Label(window, image=photo)
#puts photo in window
w.pack()
lblInst = tkinter.Label(window, text="Encrypt Message Below.", bg="#66FFFF", font=("Helvetica", 16))
#Adds title
lblInst.pack()
lblphrase = tkinter.Label(window, text="Enter phrase to be encrypted:", bg="#66FFFF", font=("Helvetica", 10))
#tells user to enter phrase
phrases = str()
phrase = tkinter.Entry(window, textvariable = phrases )
#######adds box for user to submit reply##############(I suspect this may be the root of the problem)
lblphrase.pack()
phrase.pack()
lblkeyphrase = tkinter.Label(window, text="Enter keyword:", bg="#66FFFF", font=("Helvetica", 10))
keyphrases = str()
keyphrase = tkinter.Entry(textvariable = keyphrases)
##adds box for user to submit reply#########(I suspect this may be the root of the problem)
lblkeyphrase.pack()
keyphrase.pack()
def keyword_cipher(key, phrase):
if len(phrase) > len(key):
while len(phrase) > len(key):
length_to_add = len(phrase) - len(key)
key = key + key[0:length_to_add]
#adds words together so phrase is long enough
elif len(phrase) < len(key):
while len(phrase) < len(key):
length_to_sub = len(key) - (len(key) - len(phrase))
key = key[0:length_to_sub]
else:
pass
#shift the characters
shifted_phrase = ''
for i in range(len(phrase)):
new_letter = (ord(key[i]) - 96) + (ord(phrase[i]) - 96) + 96
if new_letter > 122:
new_letter = chr(new_letter - 26)
else:
new_letter = chr(new_letter)
shifted_phrase = shifted_phrase + new_letter
return shifted_phrase
#shifts letters
lbl.configure(text = (shifted_phrase))
lbl = tkinter.Label(window, text="Nothing Yet", bg="#66FFFF", font=("Helvetica", 10))
lbl.pack()
##############This could be the problem
def lol():
keyword_cipher(keyphrases, phrases)
btn = tkinter.Button(window, text="Submit", fg="#66FFFF", bg="#383a39",command=lol())
btn.pack()
window.mainloop()
tkinter.Button(window, text="Submit", fg="#66FFFF", bg="#383a39",command=lol())
# ↑↑
This makes the lol function execute immediately. So what you pass as the keyword argument to the tkinter.Button call is the return value of lol(). So instead of lol being the command that is executed when you click the button, the return value of lol() is used as the command.
But lol() doesn’t return anything:
def lol():
keyword_cipher(keyphrases, phrases)
So there is no command bound to the button at all. Instead, pass the function itself:
tkinter.Button(…, command=lol)
Because there are no parentheses, it’s not called immediately. So the function is used as the command callback.
Note that you should do something with the return value of keyword_cipher(). For example show it somewhere in the UI.