0

I can't seem to make my new window display the inputer code

it only displays a new empty window without the labels and the input widget

i want to make a simple GUI for a school project, but i dont want to type the name in the python shell, but in the interface

please help and tell me where im wrong, im still new to python

from collections import deque
first = deque([])
last = deque([])
nom = 0
import tkinter as tk
from tkinter import *

class Application(tk.Frame):
def __init__(self, master=None, nom=0, priono=1, prio=1):
    super().__init__(master)

    self.pack()
    self.create_widgets()
    self.nom= nom
    self.priono= priono
    self.prio=prio

def create_widgets(self):
    self.add = tk.Button(self, bg ="black", fg="pink")
    self.add["text"] =   "-----Add to queue-----\n(click me)"
    self.add["command"] = self.create_window
    self.add.pack(side="top", pady = 10, padx = 20)
    self.add["font"] = "Times 16 bold"

    self.remov = tk.Button(self, bg ="black", fg="pink")
    self.remov["text"]= "---Remove in queue---\n(click me)"
    self.remov["command"] = self.remov_
    self.remov.pack(side="top", pady = 10, padx = 20)
    self.remov["font"] = "Times 16 bold"

    self.quit = tk.Button(self, text="QUIT", fg="white", bg = "red",
    command=root.destroy)
    self.quit.pack(side="bottom")

def create_window(self):
    def inputer(self):
        self.L1 = tk.Label(self, text = "Name")
        self.L1.pack( side = LEFT)
        self.E1 = tk.Entry(self, bd =5)
        self.E1.pack(side = RIGHT)
    win2 = Toplevel(self)
    win2.button = Button(self, text='Ready?\nClick Here', command=inputer)

def say_hi(self):
    print("hi there, everyone!")

def add_1(self):
    name=input("What is your name? ")
    first.append(name)
    print("Good Day!",first[self.nom])
    print("Your priority number is:","%03d" % (self.priono))
    self.priono+=1
    self.nom+= 1

def remov_(self):
    if (len(first)) >= 1:
        first.popleft()
    else:
        print("No one left in queue")


root = tk.Tk()
root.config(background="black")

app = Application(master=root)
app.master.title("ID QUEUEING SYSTEM beta")
app.master.minsize(540, 360)
app.master.maxsize(600, 500)
app.mainloop()
1
  • Try adding (fill=both, expand=True) when you are packing your frame Commented Aug 4, 2018 at 14:38

1 Answer 1

1

You must use your toplevel to indicate where the widgets must appear; you must also pack (place or grid) the widgets belonging to your toplevel window.

The code from inputer needed to be placed outside of the inner function; you can now write the code to have this inputer do what you need it to do:

I removed the star import and added the prefix tk. to all tkinter method calls.

import tkinter as tk
from collections import deque


class Application(tk.Frame):

    def __init__(self, master=None, nom=0, priono=1, prio=1):
        super().__init__(master)

        self.pack()
        self.create_widgets()
        self.nom = nom
        self.priono= priono
        self.prio=prio

    def create_widgets(self):
        self.add = tk.Button(self, bg ="black", fg="pink")
        self.add["text"] =   "-----Add to queue-----\n(click me)"
        self.add["command"] = self.create_window
        self.add.pack(side="top", pady = 10, padx = 20)
        self.add["font"] = "Times 16 bold"

        self.remov = tk.Button(self, bg ="black", fg="pink")
        self.remov["text"]= "---Remove in queue---\n(click me)"
        self.remov["command"] = self.remov_
        self.remov.pack(side="top", pady = 10, padx = 20)
        self.remov["font"] = "Times 16 bold"

        self.quit = tk.Button(self, text="QUIT", fg="white", bg = "red",
        command=root.destroy)
        self.quit.pack(side="bottom")

    def create_window(self):
        def inputer():
            print('inputer ', end=': ')
            print(self.E1.get())

        win2 = tk.Toplevel(self)
        win2_button = tk.Button(win2, text='Ready?\nClick Here', command=inputer)
        win2_button.pack()
        self.L1 = tk.Label(win2, text = "Name")
        self.L1.pack( side=tk.LEFT)
        self.E1 = tk.Entry(win2, bd =5)
        self.E1.pack(side=tk.RIGHT)

    def say_hi(self):
        print("hi there, everyone!")

    def add_1(self):
        name=input("What is your name? ")
        first.append(name)
        print("Good Day!",first[self.nom])
        print("Your priority number is:","%03d" % (self.priono))
        self.priono+=1
        self.nom+= 1

    def remov_(self):
        if (len(first)) >= 1:
            first.popleft()
        else:
            print("No one left in queue")


root = tk.Tk()
root.config(background="black")

app = Application(master=root)
app.master.title("ID QUEUEING SYSTEM beta")
app.master.minsize(540, 360)
app.master.maxsize(600, 500)
app.mainloop()
Sign up to request clarification or add additional context in comments.

1 Comment

"you must also pack the toplevel" - this is not a true statement. Toplevels are standalone windows, you can't pack them into another window.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.