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 *
#1
Hi guys, my main programs are based a lot of from subprocess call, but that is giving me problems (it doesn't matter why). I think i could write any code creating a new Top Level Window, but as you will see below, the main issue is from tkinter import * is not allowed. The new tkinter window code is only required that module. If i remove it, it will show only a window with a small, looks like a off button in the middle. And nothing of the remaining code. How can i make it work?

def next_version():
    Utilizador.set('')
    bot.set('')
    import tkinter as tk

    failure_max = 3
    passwords = [('alfa', 'nenebot'), ('alfa1', 'nenebot1'), ('alfa2', 'nenebot2'), ('alfa3', 'nenebot3'), ('alfa4', 'nenebot4'), ('alfa5', 'nenebot5')]

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

    def enter(event):
        check_password()

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

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

    root = tk.Tk()
    root_height = 160
    root_width = 300
    root.title('Login Obrigatório')
    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))
    root.geometry("{}x{}+{}+{}".format(root_width, root_height, x_cordinate, y_cordinate))

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

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

    user.focus_set()
    root.resizable(False,False)
    root.mainloop()
   
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))
    root.geometry("{}x{}+{}+{}".format(root_width, root_height, x_cordinate, y_cordinate))

    var = StringVar()
    label = Label( root, textvariable=var, relief=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()
    root.resizable(False,False)
    root.mainloop()

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
Top Level Window - from tkinter import * - by francisco_neves2020 - Apr-23-2019, 07:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 537 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 866 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,897 May-25-2023, 07:37 PM
Last Post: deanhystad
Lightbulb [Tkinter] Tkinter Class Import Module Issue AaronCatolico1 6 3,147 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,924 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,941 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,584 Feb-17-2022, 07:02 AM
Last Post: pymn
  [Tkinter] Tkinter Window Has no Title Bar gw1500se 4 2,871 Nov-07-2021, 05:14 PM
Last Post: gw1500se
  "tkinter.TclError: NULL main window" Rama02 1 5,877 Feb-04-2021, 06:45 PM
Last Post: deanhystad
  function in new window (tkinter) Dale22 7 5,191 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