user interface - Python. GUI(input and output matrices)? -


python 3.3.2 hello.my problem - need create gui input data(matrix or table).and take form data. example:

a=[[1.02,-0.25,-0.30,0.515],[-0.41,1.13,-0.15,1.555],[-0.25,-0.14,1.21,2.780]]

perfect solution restrictions input form(only float).

questions: can use? tkinter haven't table.. wxpython not supported python 3. pyqt4?(mb u have exampel how take data tabel in [[],[],[]]?)
have idea?

thnx!

using tkinter, don't need special table widget -- create grid of normal entry widgets. if have many need scrollbar it's more difficult (and there examples on site how that), create grid of small it's straightforward.

here's example includes input validation:

import tkinter tk  class simpletableinput(tk.frame):     def __init__(self, parent, rows, columns):         tk.frame.__init__(self, parent)          self._entry = {}         self.rows = rows         self.columns = columns          # register command use validation         vcmd = (self.register(self._validate), "%p")          # create table of widgets         row in range(self.rows):             column in range(self.columns):                 index = (row, column)                 e = tk.entry(self, validate="key", validatecommand=vcmd)                 e.grid(row=row, column=column, stick="nsew")                 self._entry[index] = e         # adjust column weights expand equally         column in range(self.columns):             self.grid_columnconfigure(column, weight=1)         # designate final, empty row fill space         self.grid_rowconfigure(rows, weight=1)      def get(self):         '''return list of lists, containing data in table'''         result = []         row in range(self.rows):             current_row = []             column in range(self.columns):                 index = (row, column)                 current_row.append(self._entry[index].get())             result.append(current_row)         return result      def _validate(self, p):         '''perform input validation.           allow empty value, or value can converted float         '''         if p.strip() == "":             return true          try:             f = float(p)         except valueerror:             self.bell()             return false         return true  class example(tk.frame):     def __init__(self, parent):         tk.frame.__init__(self, parent)         self.table = simpletableinput(self, 3, 4)         self.submit = tk.button(self, text="submit", command=self.on_submit)         self.table.pack(side="top", fill="both", expand=true)         self.submit.pack(side="bottom")      def on_submit(self):         print(self.table.get())   root = tk.tk() example(root).pack(side="top", fill="both", expand=true) root.mainloop() 

more input validation can found here: interactively validating entry widget content in tkinter


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -