Based on your example code one of the possibilities would be:
First screen:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""teste_interface1.py"""
import tkinter as tk
import teste_interface2
def abrir_tela_2(instance, widget):
valor = widget.get()
instance.destroy()
teste_interface2.tela2(valor)
def tela1(entry=None):
janela = tk.Tk()
janela.geometry("300x300+300+300")
janela.title('Teste interface 1')
valor_entry_interface2 = "Valor que estava no Entry da tela 1: %s" % entry
if entry is None:
valor_entry_interface2 = "Bem vindo"
label = tk.Label(janela, text=valor_entry_interface2)
label.pack()
label_interface1 = tk.Label(janela, text="Insira letras,testando a exportação:")
label_interface1.pack()
entry_interface1 = tk.Entry(janela)
entry_interface1.pack()
button_interface1 = tk.Button(janela, text="exportar",
command=lambda: abrir_tela_2(instance=janela, widget=entry_interface1))
button_interface1.pack()
janela.mainloop()
if __name__ == '__main__':
tela1()
Second screen:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""teste_interface2.py"""
import tkinter as tk
import teste_interface1
def abrir_tela_1(instance, widget):
valor = widget.get()
instance.destroy()
teste_interface1.tela1(valor)
def tela2(entry=None):
janela = tk.Tk()
janela.geometry("300x300+300+300")
janela.title('Teste interface 2')
valor_entry_interface1 = "Valor que estava no Entry da tela 1: %s" % entry
if entry is None:
valor_entry_interface1 = "Bem vindo"
label = tk.Label(janela, text=valor_entry_interface1)
label.pack()
label_interface2 = tk.Label(janela, text="Insira letras,testando a exportação:")
label_interface2.pack()
entry_interface2 = tk.Entry(janela)
entry_interface2.pack()
button_interface2 = tk.Button(janela, text="exportar",
command=lambda: abrir_tela_1(instance=janela, widget=entry_interface2))
button_interface2.pack()
janela.mainloop()
if __name__ == '__main__':
tela2()
Leaving it in a single file or separating it into several will depend on what is simpler for you to maintain or even size of the project.
The only question that demands a little more care is when working with files/scripts that will be imported, because you should use if __name__ == '__main__':
for "separate" the execution local of the archive of importing:
/a/92589/93029
What exactly do you want to import, @Antoniogally? A function, a variable, etc
– Luan Naufal
I want to export the value of a variable
– Antônio Gally