У меня есть два кадра с метками Name & Age. У меня также есть несколько типов данных в ListBox. Мои данные списка:
list1=['Tom','Harry']
list2=[ 21,45]
У меня есть два файла: unknown.py
import sys
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
import unknown_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
top = Toplevel1 (root)
unknown_support.init(root, top)
root.mainloop()
w = None
def create_Toplevel1(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = tk.Toplevel (root)
top = Toplevel1 (w)
unknown_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Toplevel1():
global w
w.destroy()
w = None
class Toplevel1:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#ececec' # Closest X11 color: 'gray92'
top.geometry("600x450+650+150")
top.title("New Toplevel")
top.configure(background="#d9d9d9")
self.Frame1 = tk.Frame(top)
self.Frame1.place(relx=0.083, rely=0.044, relheight=0.3, relwidth=0.625)
self.Frame1.configure(relief='groove')
self.Frame1.configure(borderwidth="2")
self.Frame1.configure(relief='groove')
self.Frame1.configure(background="#d9d9d9")
self.Frame1.configure(width=375)
self.Label1 = tk.Label(self.Frame1)
self.Label1.place(relx=0.053, rely=0.148, height=26, width=42)
self.Label1.configure(background="#d9d9d9")
self.Label1.configure(disabledforeground="#a3a3a3")
self.Label1.configure(foreground="#000000")
self.Label1.configure(text='''Name''')
self.Label2 = tk.Label(self.Frame1)
self.Label2.place(relx=0.053, rely=0.519, height=26, width=42)
self.Label2.configure(background="#d9d9d9")
self.Label2.configure(disabledforeground="#a3a3a3")
self.Label2.configure(foreground="#000000")
self.Label2.configure(text='''Age''')
self.Text1 = tk.Text(self.Frame1)
self.Text1.place(relx=0.373, rely=0.148, relheight=0.252, relwidth=0.357)
self.Text1.configure(background="white")
self.Text1.configure(font="TkTextFont")
self.Text1.configure(foreground="black")
self.Text1.configure(highlightbackground="#d9d9d9")
self.Text1.configure(highlightcolor="black")
self.Text1.configure(insertbackground="black")
self.Text1.configure(selectbackground="#c4c4c4")
self.Text1.configure(selectforeground="black")
self.Text1.configure(width=134)
self.Text1.configure(wrap='word')
self.Text2 = tk.Text(self.Frame1)
self.Text2.place(relx=0.373, rely=0.519, relheight=0.252, relwidth=0.357)
self.Text2.configure(background="white")
self.Text2.configure(font="TkTextFont")
self.Text2.configure(foreground="black")
self.Text2.configure(highlightbackground="#d9d9d9")
self.Text2.configure(highlightcolor="black")
self.Text2.configure(insertbackground="black")
self.Text2.configure(selectbackground="#c4c4c4")
self.Text2.configure(selectforeground="black")
self.Text2.configure(width=134)
self.Text2.configure(wrap='word')
self.Frame2 = tk.Frame(top)
self.Frame2.place(relx=0.083, rely=0.467, relheight=0.367
, relwidth=0.625)
self.Frame2.configure(relief='groove')
self.Frame2.configure(borderwidth="2")
self.Frame2.configure(relief='groove')
self.Frame2.configure(background="#d9d9d9")
self.Frame2.configure(width=375)
self.Label3 = tk.Label(self.Frame2)
self.Label3.place(relx=0.053, rely=0.182, height=26, width=42)
self.Label3.configure(background="#d9d9d9")
self.Label3.configure(disabledforeground="#a3a3a3")
self.Label3.configure(foreground="#000000")
self.Label3.configure(text='''Name''')
self.Label4 = tk.Label(self.Frame2)
self.Label4.place(relx=0.053, rely=0.485, height=26, width=42)
self.Label4.configure(background="#d9d9d9")
self.Label4.configure(disabledforeground="#a3a3a3")
self.Label4.configure(foreground="#000000")
self.Label4.configure(text='''Age''')
self.Text3 = tk.Text(self.Frame2)
self.Text3.place(relx=0.4, rely=0.182, relheight=0.206, relwidth=0.331)
self.Text3.configure(background="white")
self.Text3.configure(font="TkTextFont")
self.Text3.configure(foreground="black")
self.Text3.configure(highlightbackground="#d9d9d9")
self.Text3.configure(highlightcolor="black")
self.Text3.configure(insertbackground="black")
self.Text3.configure(selectbackground="#c4c4c4")
self.Text3.configure(selectforeground="black")
self.Text3.configure(width=124)
self.Text3.configure(wrap='word')
self.Text4 = tk.Text(self.Frame2)
self.Text4.place(relx=0.4, rely=0.485, relheight=0.206, relwidth=0.331)
self.Text4.configure(background="white")
self.Text4.configure(font="TkTextFont")
self.Text4.configure(foreground="black")
self.Text4.configure(highlightbackground="#d9d9d9")
self.Text4.configure(highlightcolor="black")
self.Text4.configure(insertbackground="black")
self.Text4.configure(selectbackground="#c4c4c4")
self.Text4.configure(selectforeground="black")
self.Text4.configure(width=124)
self.Text4.configure(wrap='word')
self.Button1 = tk.Button(top)
self.Button1.place(relx=0.767, rely=0.378, height=33, width=86)
self.Button1.configure(activebackground="#ececec")
self.Button1.configure(activeforeground="#000000")
self.Button1.configure(background="#d9d9d9")
self.Button1.configure(disabledforeground="#a3a3a3")
self.Button1.configure(foreground="#000000")
self.Button1.configure(highlightbackground="#d9d9d9")
self.Button1.configure(highlightcolor="black")
self.Button1.configure(pady="0")
self.Button1.configure(text='''Button''')
self.Button1.configure(width=86)
if __name__ == '__main__':
vp_start_gui()
и это другой файл: unknown_support.py
import sys
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
def init(top, gui, *args, **kwargs):
global w, top_level, root
w = gui
top_level = top
root = top
def destroy_window():
# Function which closes the window.
global top_level
top_level.destroy()
top_level = None
if __name__ == '__main__':
import unknown
unknown.vp_start_gui()
Я хочу, чтобы при нажатии кнопки данные из списка отображались в текстовом поле «Имя» и «Возраст».
Это должно показать как: -
В текстовых полях Frame1:
Том
21
В текстовых полях Frame2:
Гарри
45