Python Forum
[Tkinter] Top Level Window - from tkinter import *
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Top Level Window - from tkinter import *
#6
I'm not great with tkinter but i think your code should be more along the lines of the following.
I don't totally understand tkinters tk.TK(), in WxPython you create a wx.App() but they don't quite seem to be the same thing,
so i may have some of the root stuff mixed up, someone who knows tkinter may be able to tidy that up, but it works.
import tkinter as tk

class NextVersionFrame(tk.Frame):
    def __init__(self, root):
        super().__init__(root)
        self.root = root

# def next_version():
#     Utilizador.set('')
#     bot.set('')
#     import tkinter as tk
        self.failures = 0
        self.failure_max = 3
        self.passwords = [('alfa', 'nenebot'), ('alfa1', 'nenebot1'),
                 ('alfa2', 'nenebot2'), ('alfa3', 'nenebot3'),
                 ('alfa4', 'nenebot4'), ('alfa5', 'nenebot5')]



        root_height = 160
        root_width = 300
        self.root.title('Login Obrigat�rio')
        screen_width = self.root.winfo_screenwidth()
        screen_height = self.root.winfo_screenheight()
        x_cordinate = int((screen_width/2) - (root_width/2))
        y_cordinate = int((screen_height/2) - (root_height/2))
        self.root.geometry("{}x{}+{}+{}".format(
            root_width, root_height, x_cordinate, y_cordinate))

        self.user = self.make_entry("Utilizador:", 16, show='')
        self.password = self.make_entry("Password:", 16, show="*")

        b = tk.Button(
            self, borderwidth=4, text="Login", width=10, pady=8,
            command=self.check_password)
        b.pack(side=tk.BOTTOM)
        self.password.bind('<Return>', self.enter)

        self.user.focus_set()
        self.root.resizable(False,False)
        self.pack()

    def make_entry(self, caption, width=None, **options):
        tk.Label(self, text=caption).pack(side=tk.TOP)
        entry = tk.Entry(self, **options)
        if width:
            entry.config(width=width)
        entry.pack(side=tk.TOP, padx=10, fill=tk.BOTH)
        return entry

    def enter(self, event):
        self.check_password()

    def check_password(self):
        """ Collect 1's for every failure and quit program in case of failure_max failures """
        

        if (self.user.get(), self.password.get()) in self.passwords:
            self.user = self.user.get()
            NewWinFrame(self)
        self.failures += 1
        if self.failures == self.failure_max:
            self.destroy()
            raise SystemExit('Acesso Recusado')
        else:
            root.title('Tente novamente.')
        

class NewWinFrame(tk.Toplevel):
    def __init__(self, parent):
        super(NewWinFrame, self).__init__(parent)

# def new_winF():
#     from tkinter import *
 
#     root = Tk()
        root_height = 202
        root_width = 456
        screen_width = root.winfo_screenwidth()
        screen_height = root.winfo_screenheight()
        x_cordinate = int((screen_width/2) - (root_width/2))
        y_cordinate = int((screen_height/2) - (root_height/2))
        self.geometry("{}x{}+{}+{}".format(root_width, root_height, x_cordinate, y_cordinate))
     
        var = tk.StringVar()
        label = tk.Label( self, textvariable=var, relief=tk.RAISED )
     
        var.set("""     NeneBot v1.1 Beta
        ---------------------------------------------------------------------------------------------
        1� repara��o de todos os bugs reportados
        *********************************************************************************************
        2� melhorias na estrutura da App
        *********************************************************************************************
        3� melhoria na App em termos de facilidade de leitura
        *********************************************************************************************
        4� adi��o de calculadora de IP
        *********************************************************************************************
        5� organizador de ficheiros (um clique e todos os ficheiros em pasta)
        *********************************************************************************************
        6� adi��o de outras funcionalidades mediante sugest�es reportadas""")
     
        label.pack()
        self.resizable(False,False)


if __name__ == '__main__':
    root = tk.Tk()
    next_version_frame = NextVersionFrame(root)
    root.mainloop()
Reply


Messages In This Thread
RE: Top Level Window - from tkinter import * - by Yoriz - Apr-23-2019, 09:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 622 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 910 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Centering and adding a push button to a grid window, TKinter Edward_ 15 5,160 May-25-2023, 07:37 PM
Last Post: deanhystad
Lightbulb [Tkinter] Tkinter Class Import Module Issue AaronCatolico1 6 3,228 Sep-06-2022, 03:37 PM
Last Post: AaronCatolico1
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,982 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,983 Apr-16-2022, 04:04 PM
Last Post: DBox
  why my list changes to a string as I move to another window in tkinter? pymn 4 2,617 Feb-17-2022, 07:02 AM
Last Post: pymn
  [Tkinter] Tkinter Window Has no Title Bar gw1500se 4 2,900 Nov-07-2021, 05:14 PM
Last Post: gw1500se
  "tkinter.TclError: NULL main window" Rama02 1 5,917 Feb-04-2021, 06:45 PM
Last Post: deanhystad
  function in new window (tkinter) Dale22 7 5,293 Nov-24-2020, 11:28 PM
Last Post: Dale22

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020