1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PythonGUI(tkinterコンボボックス)で行列を作成

Last updated at Posted at 2020-01-13

GUI(tkinterコンボボックス)で行列の要素の値を入力し2次元配列型のデータを取得するソースです。行列のサイズ、コンボボックスのリストも変数により変更可能。

qiita.rb
from tkinter import *
from tkinter import ttk
import numpy as np


#入力用のGUI
def GUI_Input(n,m):

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

    #入力用フレーム
    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


    #コンボボックスからデータを取得し2次元配列としてpritnt出力
    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)


    #実行ボタンの設置
    button_Run = ttk.Button(root,
                            text='実行',
                            padding=5,
                            command=ButtonClicked_Run)
    button_Run.grid(row=1, column=0)

    root.mainloop()






#n、mの数を変えて、行列のサイズを指定
m = 9
n = 9
GUI_Input(m,n)

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

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?