Follow up problem from this post here: calling python code from java: askopenfilename does not work
The above error has been rectified.
I have a Java project that calls a python tkinter UI with some other python files. I wish to export this Java project into a jar/runnable jar file.
Here are the following settings I am using when exporting:
I am exporting as a runnable jar (Not sure to export as this or a jar file).
However, when I run python code and askopenfilename is executed, the whole program hangs like this:
and I cannot use windows file explorer anymore...
The python code looks like this *no change from the one in linked post above:
import os
from pathlib import Path
import tkinter as tk
from tkinter import filedialog
import startPython
from tkinter import messagebox
import threading
import sys
import datetime
import numpy
import itertools
from lxml import etree
import lxml.html
import re
import ast
import networkx as nx
import matplotlib.pyplot as plt
import pygraphviz
import base64
from networkx.drawing.nx_agraph import graphviz_layout
import plotly.graph_objects as go
root=tk.Tk()
path = Path(os.path.dirname(os.path.abspath(__file__)))
path = path.parent.absolute()
path = path.parent.absolute()
path = str(path)
path = path + '\\temp'
path = path.replace('\\','/')
print(path)
xml_old = tk.StringVar(root)
xml_new = tk.StringVar(root)
out_xml = tk.StringVar(root)
def startcompare():
try:
t = threading.Thread(target=startPython.build(xml_old.get(),xml_new.get(),out_xml.get()))
t.daemon = True
t.start()
except:
messagebox.showerror("Title", "Error. Please enter valid path")
def browsefunc1():
filename = filedialog.askopenfilename(initialdir = path,filetypes=(("xml files","*.xml"),("All files","*.*")))
ent1.delete(0, 'end')
ent1.insert(tk.END, filename) # add this
def browsefunc2():
filename = filedialog.askopenfilename(initialdir = path,filetypes=(("xml files","*.xml"),("All files","*.*")))
ent2.delete(0, 'end')
ent2.insert(tk.END, filename) # add this
def browsefunc3():
filename = filedialog.askopenfilename(initialdir = path,filetypes=(("xml files","*.xml"),("All files","*.*")))
ent3.delete(0, 'end')
ent3.insert(tk.END, filename) # add this
l0 = tk.Label(root,text = 'Enter XML files for visualization.')
l1 = tk.Label(root,text = 'old entry:')
ent1=tk.Entry(root,textvariable=xml_old)
l2 = tk.Label(root,text = 'new entry:')
ent2=tk.Entry(root,textvariable=xml_new)
l3 = tk.Label(root,text = 'out.xml:')
ent3=tk.Entry(root,textvariable=out_xml)
b1=tk.Button(root,text="...",command=browsefunc1)
b2=tk.Button(root,text="...",command=browsefunc2)
b3=tk.Button(root,text="...",command=browsefunc3)
b4=tk.Button(root,text="OK",command=startcompare)
b5=tk.Button(root,text="Cancel",command=root.destroy)