Issue
We currently have a fully functional Gui written created using PyQt. My partner wrote a function that graphs a dataSet in Tkinter. My question is, how do we combine the two so they work together?
Here is the graphing function:
def createGraph(self):
import tkinter as tk
# Send in data as param, OR
#data = [17, 20, 15, 10, 7, 5, 4, 3, 2, 1, 1, 0]
# Recieve data within function
s.send("loadgraph")
inputString = repr(s.recv(MSGSIZE))
#inputString = "-20 15 10 7 5 -4 3 2 1 1 0"
print(inputString)
data = [int(x) for x in inputString.split()]
root = tk.Tk()
root.title("FSPwners")
screen_width = 400
screen_height = 700
screen = tk.Canvas(root, width=screen_width, height=screen_height, bg= 'white')
screen.pack()
# highest y = max_data_value * y_stretch
y_stretch = 15
# gap between lower canvas edge and x axis
y_gap = 350
# stretch enough to get all data items in
x_stretch = 10
x_width = 20
# gap between left canvas edge and y axis
x_gap = 20
for x, y in enumerate(data):
# calculate reactangle coordinates (integers) for each bar
x0 = x * x_stretch + x * x_width + x_gap
y0 = screen_height - (y * y_stretch + y_gap)
x1 = x * x_stretch + x * x_width + x_width + x_gap
y1 = screen_height - y_gap
# draw the bar
print(x0, y0, x1, y1)
if y < 0:
screen.create_rectangle(x0, y0, x1, y1, fill="red")
else:
screen.create_rectangle(x0, y0, x1, y1, fill="green")
# put the y value above each bar
screen.create_text(x0+2, y0, anchor=tk.SW, text=str(y))
root.mainloop()
When that method is run by itself, it creates a popup box with the graph. Now we want it to create a popup graph when a button is pressed in our current gui. How can we get it to work? If we just call createGraph()
when a button is clicked in our GUI, we get the error:
unrecognized selector sent to instance x009x...
What is the problem? Thanks!
Solution
Qt and Tkinter don't play along quite well, as you can perceive - I had once played along Python graphical toolkits, and wrote a 4 operation calculator that would run in either Qt, GTK or Tkinter - or even display all at once.
In order to have both the Tkinter and Qt versions working simultaneously, I had to fork the process - and start each toolkit in a separate running instance;
Your case is not identical, as the Qt GUI will be already running, but maybe having this to start up with you can come along with a work-around.
The 3-calculators code listing can be found here:
https://web.archive.org/web/20101122232402/http://www.python.org.br/wiki/CalculadoraTkGtkQt
Answered By - jsbueno
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.