#!/usr/bin/env python3.6 from tkinter import* from sys import* import tkinter.ttk as ttk import tkinter.messagebox as msg from dtch import* #класс главного окна class main(): def __init__(self, master): self.master = master self.master.title(u'Объект') self.master.minsize(width=900,height=500) self.master.maxsize(width=900,height=500) self.master.resizable(width=False, height=False) nb = ttk.Notebook(master) nb.pack(fill='both', expand='yes') f1 = Frame(master, width=900,height=400) frame_dtch=Frame(f1,width=900,height=300) btnCreate=Button(f1,text=u'Создать',command=self.mCreateDtch) btnCreate.place(x=0,y=0) frame_dtch.pack() f2 = Text(master) nb.add(f1,text=u'Датчики') nb.add(f2, text=u'page2') btnCancel=Button(self.master,text=u'Отмена',command=self.evCancel).pack(side=RIGHT) btnOk=Button(self.master,text=u'Ok',command=None).pack(side=RIGHT) self.master.mainloop() #Функция выхода из приложения без сохранения данных def evCancel(self): self.master.destroy() #Открываем новое окно def mCreateDtch(self): self.dtch=dtch(self.master) # создание окна root = Tk() # запуск окна main(root)
А это код вызываемого окна по клику:
from tkinter import* from sys import* import tkinter.ttk as ttk import tkinter.messagebox as msg class dtch(): rows=2 def __init__(self,master): listPar=['time','sats','speed','cource','altitude','lon','lat','avl_driver'] self.win=Toplevel(master) self.win.title(u'Датчик') self.win.minsize(width=800,height=500) self.win.maxsize(width=800,height=500) nbf = ttk.Notebook(self.win) nbf.pack(fill='both', expand='yes') self.win.resizable(width=False, height=False) #Вкладка основное self.frameO=Frame(self.win,width=800,height=400) lName=ttk.Label(self.frameO,text='Имя*',width=30).grid(row=0,column=1,sticky=W, padx=10, pady=10) tName=Entry(self.frameO,width=50).grid(row=0,column=2,sticky=W, padx=10, pady=10) lType=Label(self.frameO,text=u'Тип датчика',width=30).grid(row=1,column=1,sticky=W, padx=10, pady=10) lIzm=Label(self.frameO,text=u'Еденица измерения:',width=30).grid(row=2,column=1,sticky=W, padx=10, pady=10) tIzm=Entry(self.frameO,textvariable=u'км',width=50).grid(row=2,column=2,sticky=W, padx=10, pady=10) lPar=Label(self.frameO,text=u'Параметр:',width=30).grid(row=3,column=1,sticky=W, padx=10, pady=10) cPar=ttk.Combobox(self.frameO,values = listPar,height=7,foreground='#FFFFFF',width=50) cPar.grid(row=3,column=2,sticky=W, padx=10, pady=10) lDir=Label(self.frameO,text=u'Описание',width=30).grid(row=4,column=1,sticky=W, padx=10, pady=10) tDir=Entry(self.frameO,width=50).grid(row=4,column=2) self.frameO.pack() # Вкладка Таблица расчетов self.frameX = Frame(self.win, width=800, height=400) self.frameXAB=Frame(self.frameX,width=400,height=400) btnAddXab=ttk.Button(self.frameXAB,text=u'Добавить',command=self.eAddXab).grid(row=0,column=1,sticky=W, padx=10, pady=10) btnDelXab = Button(self.frameXAB, text=u'Удалить', command=None).grid(row=0, column=2, sticky=W, padx=10, pady=10) lX1=Label(self.frameXAB,text='X*').grid(row=1,column=1,sticky=W, padx=10, pady=10) lA=Label(self.frameXAB,text=u'A*').grid(row=1,column=2,sticky=W, padx=10, pady=10) lB=Label(self.frameXAB,text=u'B').grid(row=1,column=3,sticky=W, padx=10, pady=10) btnDelAllXab = Button(self.frameXAB, text=u'', command=None).grid(row=1, column=4, sticky=W, padx=10, pady=10) self.frameXAB.grid(row=0,column=1) self.frameXY=Frame(self.frameX,width=400,height=400) chPareXY=Checkbutton(self.frameXY,text=u'Пары X и Y',command=None).grid(row=0, column=1, sticky=W, padx=10, pady=10) btnAddXY = Button(self.frameXY, text=u'Удалить', command=None).grid(row=0, column=3, sticky=W, padx=10, pady=10) lX2 = Label(self.frameXY, text=u'X*').grid(row=1, column=1, sticky=W, padx=10, pady=10) lY = Label(self.frameXY, text=u'Y*').grid(row=1, column=2, sticky=W, padx=10, pady=10) btnDelAllXY = Button(self.frameXY, text=u'', command=None).grid(row=1, column=3, sticky=W, padx=10, pady=10) self.frameXY.grid(row=0,column=2) self.frameX.pack(side=TOP) #Вкладка Графика self.frameGr=Frame(self.win, width=800, height=400) self.frameGr.pack(side=TOP) nbf.add(self.frameO,text=u'Основное') nbf.add(self.frameX,text='Таблица расчета') nbf.add(self.frameGr,text='График') btnCancel = Button(self.win, text=u'Отмена', command=self.eCancel).pack(side=RIGHT) btnOk = Button(self.win, text=u'Ok', command=None).pack(side=RIGHT) self.win.grab_set() self.win.focus_set() self.win.wait_window() def eCancel(self): self.win.destroy() def eAddXab(self): #b=self.frameX.grid.slaves() #msg.askokcancel('ff',b) b=rows+1 btn = Button(self.frameX, text=u'',command=None).grid(row=b,column=4,sticky=W, padx=10, pady=10)