Create a matrix with PythonGUI (tkinter combo box)

It is a source to input the values of matrix elements with GUI (tkinter combo box) and acquire 2D array type data. The size of the matrix and the list of combo boxes can also be changed by variables.

qiita.rb


from tkinter import *
from tkinter import ttk
import numpy as np


#GUI for input
def GUI_Input(n,m):

    root = Tk()
    root.title('Table Input')

    #Input frame
    frame = ttk.Frame(root)
    frame.grid(row=0, column=0)


    list_Items = [0]*(n*m)
    N = n
    M = m
    k=0
    for i in range(0, n):
        for j in range(0, m):


            valuelist = [1,2,3,4,5,6,7,8,9]
            list_Items[k] = ttk.Combobox(frame,values=valuelist,width = 2)
            list_Items[k].grid(row=i+1, column=j+1)
            k+=1


    #Get data from combo box and output pritnt as a two-dimensional array
    def ButtonClicked_Run():
        B = [0]*(N*M)

        for i in range(N*M):
            B[i] = list_Items[i].get()

        A= np.reshape(B, (N,M))
        print(A)


    #Installation of execute button
    button_Run = ttk.Button(root,
                            text='Run',
                            padding=5,
                            command=ButtonClicked_Run)
    button_Run.grid(row=1, column=0)

    root.mainloop()






#Specify the size of the matrix by changing the number of n and m
m = 9
n = 9
GUI_Input(m,n)

result スクリーンショット 2020-01-13 23.25.22.png              ⬇︎ Screenshot 2020-01-13 23.26.03.png

Recommended Posts

Create a matrix with PythonGUI (tkinter combo box)
Create a matrix with PythonGUI (text box)
Create a GUI app with Python's Tkinter
Create a frame with transparent background with tkinter [Python]
Create a GUI executable file created with tkinter
Create a native GUI app with Py2app and Tkinter
Try to dynamically create a Checkbutton with Python's Tkinter
Change the movement by changing the combo box with tkinter
[Python] Create a Tkinter program distribution file with cx_Freeze
Create a homepage with django
Create Image Viewer with Tkinter
Create a heatmap with pyqtgraph
Create a directory with python
[Python] Create a file & folder path specification screen with tkinter
Create a life game that is manually updated with tkinter
[Learning record] Create a mysterious dungeon game with Pyhton's Tkinter
Create a python GUI using tkinter
Create a poisson stepper with numpy.random
Create a file uploader with Django
Create a Python function decorator with Class
Build a blockchain with Python ① Create a class
Create a dummy image with Python + PIL.
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Create a large text file with shellscript
Create a star system with Blender 2.80 script
Create a virtual environment with Python_Mac version
Create a VM with a YAML file (KVM)
Create a simple web app with flask
Create a Python-GUI app in Docker (PySimpleGUI)
Create Excel file with Python + similarity matrix
Create a word frequency counter with Python 3.4
Create a Connecting Nearest Neighbor with NetworkX
Create a web service with Docker + Flask
Create a private repository with AWS CodeArtifact
Create a car meter with raspberry pi
Create a devilish picture with Blender scripts
Create a graph with borders removed with matplotlib
Create a LINE BOT with Minette for Python
Create a game UI from scratch with pygame2!
Create a PDF file with a random page size
Create a virtual environment with conda in Python
Create a page that loads infinitely with python
[Note] Create a one-line timezone class with python
You can easily create a GUI with Python
Create a python3 build environment with Sublime Text3
[Python] I made a Youtube Downloader with Tkinter.
Create a dashboard for Network devices with Django!
Create a color bar with Python + Qt (PySide)
Steps to create a Twitter bot with python
Create a decision tree from 0 with Python (1. Overview)
Create a new page in confluence with Python
Create a color-specified widget with Python + Qt (PySide)
How to create a Kivy 1-line input box
How to create a multi-platform app with kivy
Create a one-file hello world application with django
Create a Photoshop format file (.psd) with python
Create a Python console application easily with Click
Create a cylinder with open3d + STL file output
Create a "Hello World" (HTTP) server with Tornado
Create a translation tool with the Translate Toolkit