如何解决一旦触发按钮命令,就无法在 Tkinter 中运行下一个命令
我正在创建一个 python 脚本,每次我单击“下一步”按钮时,它都会通过更改嵌入在 URL 中的 JIRA Case Id 来打开一个新的 JIRA URL。但是当我第一次单击“下一步”按钮执行命令时,窗口停止响应,我无法在 Tkinter 窗口中再次单击。如果我关闭打开的浏览器,那么它只能让我做其他操作。
如果点击 Next 或 Prev 按钮并打开更新的 URL,下面的代码将从 Entry 小部件读取 URL,并增加/减少 case Id PROJ-T00
。
当我单击任何一个按钮时,URL 会打开,但在关闭打开的浏览器窗口之前,我无法再次单击这些按钮。
使用 lambda 也没有解决问题
import webbrowser
from tkinter import *
import os
root = Tk()
root.wm_attributes("-topmost",1)
root.geometry("600x150")
newTab = IntVar()
newBrowser = IntVar()
input_url = StringVar()
chrome_path = 'C:/Program Files/Google/Chrome/Application/chrome.exe %s'
initURL = 'https://jira.****.***/../testCase/PROJ-T01'
def nextUrl():
url = input_url.get()
baseUrl = url.rsplit('T',1)[0] + 'T'
curentCaseId = int(url.rsplit('T',1)[-1])
caseId = curentCaseId + 1
url = baseUrl + str(caseId)
print(url)
name_entry.delete(0,"end")
name_entry.insert(0,url)
webbrowser.get(chrome_path).open(url,new=0)
def prevUrl():
url = input_url.get()
baseUrl = url.rsplit('T',1)[-1])
caseId = curentCaseId - 1
url = baseUrl + str(caseId)
print(url)
name_entry.delete(0,new=0)
def openUrl():
print(input_url.get())
webbrowser.get(chrome_path).open(input_url.get(),new=0)
select_msg = Label(root,text = "Current URL")
name_entry = Entry(root,textvariable = input_url,font=('calibre',10,'normal'),width=83)
name_entry.insert(0,initURL)
l1 = Checkbutton(root,text='Open in New Tab',variable=newTab,onvalue=1,offvalue=0)
l2 = Checkbutton(root,text='Open in New Browser',variable=newBrowser,offvalue=0)
prev = Button(root,text = 'Prev Case',command= prevUrl)
open = Button(root,text = 'Open Case',command= openUrl)
next = Button(root,text = 'Next Case',command= nextUrl)
select_msg.grid(row=0,column=0,columnspan=3)
name_entry.grid(row=1,columnspan=3,padx = 5)
l1.grid(row=2,column=0)
l2.grid(row=2,column=2)
prev.grid(row=3,column=0)
open.grid(row=3,column=1)
next.grid(row=3,column=2)
root.mainloop()
`
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。