简体   繁体   中英

how can i open another window in tkinter from another file?

i have a problem in my code in python (tkinter) I have two files (ger_dentista.py) and (ger_paciente.py), each is a window, and I have another file called (main.py) that opens a window with two buttons, I want to click one of the (ger_dentista) files every time Or (ger_paciente) open. the window only opens one time, I'm using linux.

from tkinter import *

from tkinter import ttk



root =  Tk()

class funcoes():


def janela2(self):
    import ger_dentista
    

def janela3(self):
    import ger_pacientes


class application(funcoes):


def __init__(self):
    self.root = root
    self.tela()
    self.frames_da_tela()
    self.widgets_frame()
    root.mainloop()

def tela(self):
    self.root.title('ODONTO DIGITAL')
    self.root.configure(background='#483D8B')
    self.root.geometry('800x600')
    self.root.resizable(True, True)
    self.root.minsize(width=600, height=480)

def frames_da_tela(self):
    self.frame_1 = Frame(self.root)
    self.frame_1.place(relx= 0.25, rely= 0.25, relwidth= 0.50, relheight= 0.46)

def widgets_frame(self):
    self.bt_dentista = Button(self.frame_1, text='Gerenciar dentistas', command=self.janela2)
    self.bt_dentista.place(relx=0.3, rely=0.21, relwidth=0.35, relheight=0.12)
    
    self.bt_paciente = Button(self.frame_1, text='Gerenciar pacientes', command=self.janela3)
    self.bt_paciente.place(relx=0.3, rely=0.34, relwidth=0.35, relheight=0.12)
    
    self.bt_consulta = Button(self.frame_1, text='Gerenciar Consultas')
    self.bt_consulta.place(relx=0.3, rely=0.48, relwidth=0.35, relheight=0.12)

    self.bt_sair = Button(self.frame_1, text='Sair')
    self.bt_sair.place(relx=0.3, rely=0.62, relwidth=0.35, relheight=0.12)   

    self.lb_pesquisar = Label(self.frame_1, text='O que deseja fazer?')
    self.lb_pesquisar.place(relx=0.32 , rely=0.04)

application()

Use os module to open another script.

Example:

import os

os.startfile('C:/Users/my/Desktop/programming/tkinter/app.py')
#put in brackets your location to script, above location is just to demonstrate

And little coment to your code:

dont use from tkinter import * , use for example import tkinter as tk and if you need widget or something you can use for example from tkinter import Button

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM