Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Python GUI not worling properly with OS path

i am trying to develop a code in python for power bi such that for every even compilation it does fixed set of instructions and for odd compilations it opens a GUI to get a 3D contour plot. The code is perfectly working in python but its not showing any output in power bi.

here is the code :


import os.path
import tkinter as tk
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.tri as tri
from scipy.interpolate import griddata
import numpy as np
from tkinter import filedialog, messagebox, ttk

#%%
colors=(['viridis', 'plasma', 'inferno', 'magma', 'cividis','Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn'])
#%%
if os.path.isfile('flag.txt'😞
with open('flag.txt', 'r') as f:
try:
count = int(f.read().strip())
except ValueError as e:
print(f"Error: {e}")
print("Flag file contents:", f.read())
count = 0
 
# Increment the count and write it back to the file
count += 1
with open('flag.txt', 'w') as f:
f.write(str(count))
 
# Check if the count is even or odd
if count % 2 != 0:
print("Even compilation number")
#axes defination
dataset=pd.read_excel(r"20230201_PTP02.xlsx")

 
z=round(dataset["GasRailP_pFild"])
x=(round(dataset["Epm_nEng"],))
y=(round(dataset["rl_w_msg"],))
 
plt.show()
else:
root = tk.Tk()
root.title("User Input")
var = tk.StringVar()
x_label = tk.Label(root, text="Delta of x axis:")
x_label.pack()
x_entry = tk.Entry(root)
x_entry.insert(0, 200)
x_entry.pack()

y_label = tk.Label(root, text="Delta of y axis:")
y_label.pack()
y_entry = tk.Entry(root)
y_entry.insert(0, 100)
y_entry.pack()

z_label = tk.Label(root, text="set color:")
z_label.pack()
clicked = tk.StringVar()
clicked.set(colors[8])
drop=ttk.Combobox(root,textvariable=clicked,value=colors)
drop.pack()
 
start=tk.Label(root, text="isoline minimum")
start.pack()
entry= tk.Entry(root)
entry.insert(0,0)
entry.pack()
 
end=tk.Label(root, text="isoline maximum")
end.pack()
entry2= tk.Entry(root)
entry2.insert(0,100)
entry2.pack()
 
delta=tk.Label(root, text="isoline delta")
delta.pack()
entry3= tk.Entry(root)
entry3.insert(0,100)
entry3.pack()

def submit():
 
submit_button = tk.Button(root, text="Submit", command=lambda: submit())
submit_button.pack()
# Start the GUI loop
root.mainloop()
 
else:
# If the flag file doesn't exist, this is the first time the code is run
# Create the flag file with a count of 1
with open('flag.txt', 'w') as f:
f.write('1')
 
Status: Needs Info
Comments
Anonymous
Not applicable

Hi @Anonymous 

What should the correct display look like? Is there no error message in Power BI?

 

Best Regards,
Community Support Team _ Ailsa Tao

Anonymous
Not applicable

There is no error message , it is telling NO image was created by python .

 

Regarding display and all , code is perfectly working in jupiter notebook , but not working in power bi

Anonymous
Not applicable

Hey ,

could anyone look up on this problem . It would be of great help