Python Forum
[python] [Tkinter] Problem bidding combobox with np.array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[python] [Tkinter] Problem bidding combobox with np.array
#1
I want to include combobox values into np.array taken from function but it does not work. Could you please help me to make it workable. I will appreciate your help.

import tkinter as tk
from tkinter.ttk import *


import numpy as np
import pandas as pd

from scipy.stats import norm


master = tk.Tk()

v = tk.IntVar()
combo = Combobox(master)




def callback(event):
    a = [float(w1.get()),float(w2.get()),float(w3.get()),float(w4.get())]
   
    print(a)
   


w1 = Combobox(master)
w1['values']= (0.2,0.3,0.4,0.1)
w1.current(0) #set the selected item
w1.grid(row=3, column=2)



w2= Combobox(master)
w2['values']= (0.2,0.3,0.4,0.1)
w2.current(0) #set the selected item
w2.grid(row=4, column=2)



w3= Combobox(master)
w3['values']= (0.2,0.3,0.4,0.1)
w3.current(0) #set the selected item
w3.grid(row=5, column=2)



w4= Combobox(master)
w4['values']= (0.2,0.3,0.4,0.1)
w4.current(0) #set the selected item
w4.grid(row=6, column=2)
w4.bind("<<ComboboxSelected>>", callback)



weights = np.array([a])


master.mainloop()
Reply
#2
In weights = np.array([a]) a has not been defined

There is an a local to the function callback this a wont have any values until w4 Combobox has been selected which will call the function callback and is only accessible in that function.
Reply
#3
(Aug-04-2019, 10:50 AM)Yoriz Wrote: In weights = np.array([a]) a has not been defined There is an a local to the function callback this a wont have any values until w4 Combobox has been selected which will call the function callback and is only accessible in that function.


So what to do ? I tried to make a global but instead it gives me random values from the values. Could you please help?
Reply
#4
It depends on what you are trying to do with
weights = np.array([a])
If you moved it to the function it would be created when the callback happens

def callback(event):
    a = [float(w1.get()),float(w2.get()),float(w3.get()),float(w4.get())]
    
    print(a)
    weights = np.array([a])
but you would not be able to access weights outside of the call back.

You would have a better time using classes for GUI code.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] How can I sync Combobox index to other combobox index? nickzsche 2 2,332 Jan-03-2022, 12:29 PM
Last Post: Axel_Erfurt
  Python3 tkinter radiobutton problem Nick_tkinter 14 5,832 Feb-15-2021, 11:01 PM
Last Post: Nick_tkinter
  tkinter python button position problem Nick_tkinter 3 3,486 Jan-31-2021, 05:15 AM
Last Post: deanhystad
Question [Tkinter] Can I set background color for each item in tkinter Combobox? water 1 5,058 Dec-10-2020, 07:48 PM
Last Post: Larz60+
  [Tkinter] ClockIn/Out tkinter problem Maryan 2 2,165 Oct-12-2020, 03:42 AM
Last Post: joe_momma
  tkinter| listbox.insert problem Maryan 3 3,438 Sep-29-2020, 05:34 PM
Last Post: Yoriz
  Convert combobox user input in to date with tkinter Ame 8 6,658 Jul-01-2020, 09:40 PM
Last Post: Yoriz
  Tkinter problem DPaul 6 4,048 May-28-2020, 03:40 PM
Last Post: DPaul
  [PyQt] Control a combobox from another python file PyQt5 prath 0 2,242 May-05-2020, 03:22 PM
Last Post: prath
  [Tkinter] Tkinter - I have problem after import varaible or function from aGUI to script johnjh 2 2,521 Apr-17-2020, 08:12 PM
Last Post: johnjh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020