Python 为我的程序创建GUI
我试图用Python为我的编码程序创建一个GUI。问题是它似乎不能同时工作。我是Python的初学者,所以我还不确定所有东西是如何工作的。我已经在互联网上寻找解决方案,但一无所获 到目前为止,我的计划是Python 为我的程序创建GUI,python,user-interface,Python,User Interface,我试图用Python为我的编码程序创建一个GUI。问题是它似乎不能同时工作。我是Python的初学者,所以我还不确定所有东西是如何工作的。我已经在互联网上寻找解决方案,但一无所获 到目前为止,我的计划是 def program (str,my_fn): global i i=0 while i<len(str): my_fn() i += 1 def encrypt(my_result,str,number=0): my_r
def program (str,my_fn):
global i
i=0
while i<len(str):
my_fn()
i += 1
def encrypt(my_result,str,number=0):
my_result.append(ord(str[i])-number)
def decrypt(my_result,str,number=0):
my_result.append(chr(str[i]+number))
def password_generator():
password = input("What would the password be:\n")
numerical_password=[]
program(password,partial(encrypt,numerical_password,password))
global code
code = sum(numerical_password)
while choice != "Exit":
choice = input("Do you want to Encrypt, Decrypt, or Exit?\n")
if choice == "Encrypt": #Encrypt
option = input("Do you want a password?(Yes or No)\n")
if option == "Yes":
password_generator()
else:
code = 0
answer = input("What would you like to encrypt:\n")
message = []
program(answer,partial(encrypt,message,answer,code))
print (message)
if choice == "Decrypt": #Decrypt
option = input("Do you have a password?(Yes or No)\n")
code= 0
if option == "Yes":
password_generator()
else:
code = 0
answer = [int(x) for x in input("(Please insert ONLY intergers seperated with commas)\nWhat would you like to decrypt:\n").split(",")]
text =[]
program(answer, partial(decrypt,text,answer,code))
print("".join(text))
print("ThAnK yOu foR uSiNg eNcodER. HAve a nICe dAY!")
我的目标是,当按下按钮1时,它将允许用户加密他们想要的字符串
非常感谢 从技术上讲,对于同时执行,应该使用,但这不太适合您的代码。我建议将代码主体转换为函数。这应该很简单。而不是:
while choice != "Exit":
choice = input("Do you want to Encrypt, Decrypt, or Exit?\n")
...
写
这会解决你的问题;只需将
choice==“Encrypted”
替换为make_choice(“Encrypted”)
或任何您需要的选择。希望这有帮助 我认为Easygui对你来说可能很方便。那么我会把函数放在创建GUI的循环中吗;没有澄清这一点。您应该将def Button1():choice==“Encrypted”
替换为def Button1():make_choice(“Encrypted”)
,替换为与您希望执行的任何功能相对应的其他按钮中的Encrypted
。
while choice != "Exit":
choice = input("Do you want to Encrypt, Decrypt, or Exit?\n")
...
def make_choice(choice = None):
if choice is None:
choice = input("Do you want to Encrypt, Decrypt, or Exit?\n")
...