0

A interface funciona, mas aparece dividida; parte do código numa janela e parte em outra. O código foi originalmente gerado com o PAGE, mas daí eu alterei pra tanto me livrar do arquivo de suporte quanto deixar em OO, mas como não entendo muito de tk, acabei me perdendo.

import sys
import tkinter as tk
import tkinter.ttk as ttk

class menuPrincipal:
    def __init__(self):
        _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'
        self.style = ttk.Style()
        if sys.platform == "win32":
            self.style.theme_use('winnative')
        self.style.configure('.',background=_bgcolor)
        self.style.configure('.',foreground=_fgcolor)
        self.style.configure('.',font="TkDefaultFont")
        self.style.map('.',background=
            [('selected', _compcolor), ('active',_ana2color)])    

        self.Canvas1 = tk.Canvas()
        self.Canvas1.place(relx=0.018, rely=0.023, relheight=0.95
                , relwidth=0.964)
        self.Canvas1.configure(background="#d9d9d9")
        self.Canvas1.configure(borderwidth="2")
        self.Canvas1.configure(insertbackground="black")
        self.Canvas1.configure(relief="ridge")
        self.Canvas1.configure(selectbackground="#c4c4c4")
        self.Canvas1.configure(selectforeground="black")

        self.EntradaInput = ttk.Entry(self.Canvas1)
        self.EntradaInput.place(relx=0.047, rely=0.323, relheight=0.085
                , relwidth=0.904)
        self.EntradaInput.configure(takefocus="")
        self.EntradaInput.configure(cursor="ibeam")

        self.Confirmar = ttk.Button(self.Canvas1,command=lambda:self.pegar(self.EntradaInput))
        self.Confirmar.place(relx=0.281, rely=0.605, height=25, width=76)
        self.Confirmar.configure(takefocus="")
        self.Confirmar.configure(text='''Confirmar''')

        self.Encerrar = ttk.Button(self.Canvas1,command=lambda:sys.exit(1))
        self.Encerrar.place(relx=0.539, rely=0.605, height=25, width=76)
        self.Encerrar.configure(takefocus="")
        self.Encerrar.configure(text='''Encerrar''')

        self.Numeros = ttk.Label(self.Canvas1)
        self.Numeros.place(relx=0.351, rely=0.202, height=19, width=126)
        self.Numeros.configure(background="#d9d9d9")
        self.Numeros.configure(foreground="#000000")
        self.Numeros.configure(font="TkDefaultFont")
        self.Numeros.configure(relief="flat")
        self.Numeros.configure(anchor='w')
        self.Numeros.configure(justify='left')
        self.Numeros.configure(text='''Insira seus números:''')

    def iniciar(self):
        global root
        root = tk.Tk()
        root.geometry("443x261+360+115")
        root.minsize(120, 1)
        root.maxsize(1370, 749)
        root.resizable(1, 1)
        root.title("Menu principal")
        root.configure(background="#d9d9d9")
        root.mainloop()

    def encerrar(self):
        root.quit()

    def pegar(self, entry):
        self.numInput = entry.get()
        self.encerrar()

1 Resposta 1

0

Consegui, enfim! Foi na tentativa-e-erro, mas para caso alguém venha a encontrar isso no futuro:

import sys
import tkinter as tk
import tkinter.ttk as ttk

class menuPrincipal:
    def __init__(self):
        global root
        root = tk.Tk()
        root.geometry("443x261+360+115")
        root.minsize(120, 1)
        root.maxsize(1370, 749)
        root.resizable(1, 1)
        root.title("Menu principal")
        root.configure(background="#d9d9d9")

        _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'
        self.style = ttk.Style()
        if sys.platform == "win32":
            self.style.theme_use('winnative')
        self.style.configure('.',background=_bgcolor)
        self.style.configure('.',foreground=_fgcolor)
        self.style.configure('.',font="TkDefaultFont")
        self.style.map('.',background=
            [('selected', _compcolor), ('active',_ana2color)])    

        self.Canvas1 = tk.Canvas(root)
        self.Canvas1.place(relx=0.018, rely=0.023, relheight=0.95
                , relwidth=0.964)
        self.Canvas1.configure(background="#d9d9d9")
        self.Canvas1.configure(borderwidth="2")
        self.Canvas1.configure(insertbackground="black")
        self.Canvas1.configure(relief="ridge")
        self.Canvas1.configure(selectbackground="#c4c4c4")
        self.Canvas1.configure(selectforeground="black")

        self.EntradaInput = ttk.Entry(self.Canvas1)
        self.EntradaInput.place(relx=0.047, rely=0.323, relheight=0.085
                , relwidth=0.904)
        self.EntradaInput.configure(takefocus="")
        self.EntradaInput.configure(cursor="ibeam")

        self.Confirmar = ttk.Button(self.Canvas1,command=lambda:self.pegar(self.EntradaInput))
        self.Confirmar.place(relx=0.281, rely=0.605, height=25, width=76)
        self.Confirmar.configure(takefocus="")
        self.Confirmar.configure(text='''Confirmar''')

        self.Encerrar = ttk.Button(self.Canvas1,command=lambda:sys.exit(1))
        self.Encerrar.place(relx=0.539, rely=0.605, height=25, width=76)
        self.Encerrar.configure(takefocus="")
        self.Encerrar.configure(text='''Encerrar''')

        self.Numeros = ttk.Label(self.Canvas1)
        self.Numeros.place(relx=0.351, rely=0.202, height=19, width=126)
        self.Numeros.configure(background="#d9d9d9")
        self.Numeros.configure(foreground="#000000")
        self.Numeros.configure(font="TkDefaultFont")
        self.Numeros.configure(relief="flat")
        self.Numeros.configure(anchor='w')
        self.Numeros.configure(justify='left')
        self.Numeros.configure(text='''Insira seus números:''')

    def iniciar(self):
        root.mainloop()

    def encerrar(self):
        root.quit()

    def pegar(self, entry):
        self.numInput = entry.get()
        self.encerrar()

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .