Is it possible to create a pop-up input window for a numpy array?
Question:
I am fairly new to Python and I am trying to make my code more user friendly with some Pop-up input windows.
I would like to get an numpy.array
from an input window. I have looked everywhere but can´t find any example. Is it possible?
Example of array:
a = np.array ([0,1,2,3])
Thank you
Answers:
Well you just want a window to pop up to enter the details, so just try this out:
import tkinter as tk
from tkinter import simpledialog, messagebox
import numpy as np
root = tk.Tk() #creating a tcl interpreter
root.withdraw() #hiding the window
entry = simpledialog.askstring('Input Popup', 'Enter the numbers separated by commas') #creating a pop up window
try:
lst = [int(x) for x in entry.split(',')]
print(np.array(lst)) #print the array of it out.
except (AttributeError,ValueError):
messagebox.showerror('Invalid input','Enter an proper valid input') #to show error message in a window
finally:
root.destroy() #destroying the window finally
I’ve explained the code with comments to understand on-the-go, though keep in mind the user has to give input as 1,2,3,4(comma separated format).
I am fairly new to Python and I am trying to make my code more user friendly with some Pop-up input windows.
I would like to get an numpy.array
from an input window. I have looked everywhere but can´t find any example. Is it possible?
Example of array:
a = np.array ([0,1,2,3])
Thank you
Well you just want a window to pop up to enter the details, so just try this out:
import tkinter as tk
from tkinter import simpledialog, messagebox
import numpy as np
root = tk.Tk() #creating a tcl interpreter
root.withdraw() #hiding the window
entry = simpledialog.askstring('Input Popup', 'Enter the numbers separated by commas') #creating a pop up window
try:
lst = [int(x) for x in entry.split(',')]
print(np.array(lst)) #print the array of it out.
except (AttributeError,ValueError):
messagebox.showerror('Invalid input','Enter an proper valid input') #to show error message in a window
finally:
root.destroy() #destroying the window finally
I’ve explained the code with comments to understand on-the-go, though keep in mind the user has to give input as 1,2,3,4(comma separated format).