I am writing a script in Python 3.8.7 using the P4Python interface for our Perforce server. There are some circumstances where I don´t want to abort the submit of changes, but I need to inform the user about some information. For that purpose I wanted to use messagebox from the tkinter library. If the script get´s executed by perforce, the messagebox does not appear, but if I run it in a terminal, it works as expected.
Any clue how I can solve this problem.
Here is a code snippet of my script, where I want that the messagebox appears.
def setupConnection(cfg):
connectionError = False
exit = False
errorMsg = ""
while not exit:
try:
client = http.client.HTTPConnection(cfg.serverAddress)
client.connect()
except:
connectionError = True
errorMsg = "Address " + cfg.serverAddress + " is not available! Check connection or configuration."
#sys.exit("Address " + cfg.serverAddress + " is not available! Check connection or configuration.")
if not connectionError:
client.request(method=GET, url=cfg.apiAddress, headers=cfg.headers)
response = client.getresponse()
if response.status == pageNotFound404:
connectionError = True
errorMsg = "Address " + cfg.apiAddress + " is not available! Check connection or configuration."
#sys.exit("Address " + cfg.apiAddress + " is not available! Check connection or configuration.")
else:
cfg.apiGetResponse = (response.read()).decode()
exit = True
return client
if connectionError:
window = Tk()
window.eval('tk::PlaceWindow %s center' % window.winfo_toplevel())
window.withdraw()
if not messagebox.askretrycancel('Connection error', errorMsg, icon='error'):
exit = True
errorMsg = ('Please add changelist ' + cfg.changelist_ID + ' in ' + cfg.customFieldName + ' textbox of workpackage ' + cfg.workpackage_ID)
messagebox.showinfo('User action required', errorMsg)
window.destroy()
window.quit()
return None
Triggers are defined and executed on the server. If you pop a message box up on the server, the client isn't going to see it. Instead, your script should print the message to stdout; the server will pick it up and send it to the client (which can print it to the console or put it in a GUI window or whatever is appropriate to that client app).