0

****EDIT*** I just made my img and panel global , but i want them be in same line , how can i do that?

this is what is see now: enter image description here

I am trying to display some image but something goes wrong and I can't see my image. I understood that the problem is with other functions that I wrote (kmean), there I displayed a plot on my Tkinter. if I hide this function so the image works and display well

Cluster class:

 def kmean(self,df,top):
        result = KMeans(n_clusters=int(self.k), n_init=int(self.iterations)).fit(df)
        kmeans = result.predict(df)
        df['kMeans'] = kmeans
        figure = Figure(figsize=(5,5))
        plt=figure.add_subplot(111)
        canvas = FigureCanvasTkAgg(figure, top)
        canvas.get_tk_widget().grid(row=10, column=0, columnspan=5, padx=600, pady=200)
        figure.suptitle('K-Means Clustering', fontsize=16)
        plt.set_xlabel('Social support', fontsize=16)
        plt.set_ylabel('Generosity', fontsize=16)
        plt.scatter(df['Generosity'], df['Social support'], c=result.labels_.astype(float))
        canvas.draw()

Gui class: here I am trying to display image but its dosn`t works

         def cluster(self):
             cluster = Cluster(self.kNum,self.runs)
             cluster.kmean(self.dataFrame.df,top)
             cluster.countries(self.dataFrame.df)

             im=Image.open("name.png")
             img = ImageTk.PhotoImage(im)
             panel = Label(top, image=img)
             panel.image = img
             panel.grid()

someone can explain to me what the problem please?

3
  • 1
    try global panel,img inside your cluster method Jun 12, 2020 at 21:06
  • its looks that its works now , but there is a new issue , i just edited my post
    – John Doe
    Jun 13, 2020 at 5:34
  • what positioning system are you using,if it is grid() specify it to be in same row and diff column like .grid(row=0,column=0) and .grid(row=0,column=1) Jun 13, 2020 at 11:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.