私は計算結果を表示するウィンドウをtkinterに作成しようとしています。グラフと小さなテーブルが必要です。私は彼らに必要な方法でそれらを手配することはできません。以下は例のコードです。この場合、グラフとテーブルは1つのみ表示します。tkinterのウィンドウ内のテーブルの場所を変更します。
import matplotlib
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import tkinter as tk
from tkinter import ttk
import numpy as np
import pandas as pd
df1 = pd.DataFrame(np.random.randint(0,30,size=(15, 3)), columns=list('ABC'))
df1['index'] = df1.index
l1 = [1,2,3,4,5]
l2 = [6,7,8,9,10]
l3 = [100,200,300,400,500]
root = tk.Tk()
lf = ttk.Labelframe(root, text='Results')
lf.grid(row=0, column=0, sticky='nwes', padx=3, pady=3)
fig = Figure(figsize=(10,5), dpi=70)
ax = fig.add_subplot(111)
df1.plot(x='index', y=['A', 'B', 'C'], ax=ax)
canvas = FigureCanvasTkAgg(fig, master=lf)
canvas.show()
canvas.get_tk_widget().grid(row=0, column=0)
label = ttk.Label(root, text= 'Res_values')
label.config(font=("Courier", 20))
label.place(x = 810, y = 70)
li1 = l1
li2 = l2
li3 = l3
list1 = tk.Listbox(root)
list2 = tk.Listbox(root)
list3 = tk.Listbox(root)
for item in li1:
list1.insert(0,item)
for item in li2:
list2.insert(0,item)
for item in li3:
list3.insert(0,item)
list1.grid(row=0, column=1)
list2.grid(row=0, column=2)
list3.grid(row=0, column=3)
root.mainloop()
コード実行の結果は次のようになります
Iテーブルが高く、グラフの近くに配置されたいと列が小さくなります。その
同様
は、それがこれを行うことは可能ですか?
:UPDは私がどこ
label = ttk.Label(root, text= 'Res_values')
label.config(font=("Courier", 20))
label.grid(row=0, column = 1, columnspan=3, sticky='N')
そして
list1.grid(row=1, column=1, sticky='E'+'W')
list2.grid(row=1, column=2, sticky='E'+'W')
list3.grid(row=1, column=3, sticky='E'+'W')
は、結果はこのようになりますテーブルを配置することが示されているコードの一部を変更しました
誰かが私が間違っていることを説明してもらえますか?
あなたの編集に応答するには、 'LabelFrame'の' rowspan'引数を2に変更して、すべてがあなたの望むように再配置できるようにします。 – SneakyTurtle