他のリストの要素から名前の新しいリストを作成し、いくつかのエラーが発生します。 title_list = [A, B, C]
がある場合、私はリストの元を作りたい)B.append(test_items)
どのように私は、他のリストの要素から、リスト名を使用するようにwnat
from tkinter import Tk, Button, Entry
import tkinter as tk
ent1_input = []
ent2_input = []
title_list = []
test_item_list = []
entry1 = 0
entry2 = 0
def addentry():
ent1 = Entry(root)
ent1.pack()
ent1_input.append(ent1)
def click_B():
global title
for entry1 in ent1_input:
title = entry1.get()
create_window()
title_list.append(title)
def create_window():
def addBox2():
ent2 = Entry(new_root)
ent2.pack()
ent2_input.append(ent2)
def test_item_list_up():
global test_items
for i in range(0, len(title_list)):
for entry2 in ent2_input:
test_items = entry2.get()
title_lsit[i].append(test_items) # <---- What do i change it
new_root = tk.Tk()
new_root.geometry('200x200')
addboxButton = Button(new_root, text= title , command=addBox2)
addboxButton.pack(side="top", expand=True, padx=1, pady=1)
applyButton = Button(new_root, text="Apply value",command=test_item_list_up)
applyButton.pack(side="bottom", expand=True, padx=1, pady=1)
root = Tk()
root.geometry('200x200')
root.title('initialization')
root.configure(background='green')
b = Button(root, text="Set Items", command=addentry)
b.pack(side="top", expand=True, padx=1, pady=1)
c = Button(root, text="Apply Items", command=click_B)
c.pack(side="bottom", expand=True, padx=1, pady=1)
root.mainloop()
これは、いくつかのサンプルコードの可能な図であり、私は数週間のためにのPythonを勉強してきました。
それはあなたが求めているものは明らかではありません。あなたが問題に直面していると思われる関連コードのみを投稿してください。入力リストと必要な出力について言及してください。 –
lsitのA = [ABC、XYZ、RGB] 私は リストABC = [...] リストXYZ = [...] リストRGB = [...]以下のように新しいリストを作りたいです 既存のリストの要素を新しい名前として使用したいと考えています。 – Backjunee
リストから文字列を取り出し、その文字列を新しい変数の名前として使用しようとしているようです。あれは正しいですか?もしそうなら、それをしないでください。動的に作成された変数名は、コードの理解とデバッグを非常に困難にし、実際の価値を提供しません。なぜデータを変数名として使用する必要があるのか説明できますか?あなたはどんな問題を解決すると思いますか? –