我正在试着做一个基本莫尔斯电码翻译器。我希望它首先显示一个窗口,让您可以选择不同的模式。我希望能够选择翻译模式,然后将窗口更改为“翻译屏幕”,然后运行翻译功能
相反,当我选择我的模式时,它会运行该功能,然后一旦该功能完成,它就会切换到“翻译屏幕”
我尝试过改变事情运行的顺序,但没有任何效果。我不知道该怎么办。我也没有用tkinter很久
此功能用于在选择模式后更改窗口并运行功能
def choose(selected):
allOff()#this turns off led
if selected.get() == 1:
print("1")
root.title("Translate")
trans.grid(column=2, row=0)#shows a label
backButton.grid(column=2, row=5)# shows a button
againBtn.grid(column=2, row=4)#shows another button
clear() #this is to clear the widgets from the choosing screen
transColorOn() #this just turns on an led
translate() #this is the translate function
这是translate函数
def translate():
global i, LetterToSend
inBruh()
i = 0
while i < len(morse):
if LetterToSend == morse[i]:
print("" + (alphabet[i]))
letterBig = alphabet[1]
break
i += 1
LetterToSend = ""
这是输入函数
def inBruh():
global LetterToSend
LetterToSend = ""
tempIN = input(". or - , then done\n")
while tempIN != "done":
if tempIN == ".":
LetterToSend = "" + LetterToSend + "."
print("" + (LetterToSend))
tempIN = input(". or - , then done\n")
elif tempIN == "-":
LetterToSend = "" + LetterToSend + "-"
print("" + (LetterToSend))
tempIN = input(". or - , then done\n")
else:
print("plsss valid input\n")
tempIN = input(". or - , then done\n")
帮助 谢谢
由于您的问题中缺少信息,我对代码进行了一些修改,使其能够正常工作
我使用了一个框架来创建初始的小部件集,后来被称为
frame.pack_forget()
,它临时删除框架及其子小部件,然后将新的小部件集打包到根目录上(您也可以在另一个框架上进行打包),只要您需要返回初始屏幕,就可以调用frame.pack()
。可以以相同的方式将其与任何几何图形管理器一起使用。让我知道这是你的问题还是我解释错了相关问题 更多 >
编程相关推荐