-1

I'm creating an application using tktinter in python. I created a button called 'New Task' which calls a upon a function where the user can enter in a link, i then created another button, where another function is called upon, where the link the user inputtedis printed out in the console, but for some reason it prints nothing every time. Please help, Heres the code

from tkinter import *
from tkinter.ttk import *
import tkinter as tk              
LARGE_FONT= ("Verdana", 12)


class SeaofBTCapp(tk.Tk):

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand = True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        for F in (Task,LoginPage):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column = 0, sticky="nsew")

        self.show_frame(Task)

    def show_frame(self, cont):
        #for frame in self.frames.values():
            #frame.grid_remove()

        frame = self.frames[cont]
        frame.tkraise()
        frame.winfo_toplevel().geometry("1024x720")
        frame.configure(bg='#333130')
class LoginPage(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text=" Page 1", font=LARGE_FONT)
        label.pack(pady=10, padx=10)
        #loggedin(self, parent, controller)
class Task(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        c = Canvas(self, height=50, width=102400, bg="#333130")
        c.pack()
        homebutton = tk.Button(self, text='Home', command=lambda: controller.show_frame(HypeExtractor))
        homebutton_window = c.create_window(10, 12.5, anchor=tk.NW, window=homebutton)
        taskbutton = tk.Button(self, text='Task', command=lambda: controller.show_frame(Task))
        taskbutton_window = c.create_window(104, 12.5, anchor=tk.NW, window=taskbutton)
        adressbutton = tk.Button(self, text='Your Adressess', command=lambda: controller.show_frame(YourAdressess))
        adressbutton_window = c.create_window(196, 12.5, anchor=tk.NW, window=adressbutton)
        paymentbutton = tk.Button(self, text='Payment', command=lambda: controller.show_frame(Payment))
        paymentbutton_window = c.create_window(323, 12.5, anchor=tk.NW, window=paymentbutton)
        newtaskbutton = tk.Button(self, text='New Task',command=lambda: taskcreator())
        newtaskbutton_window = c.create_window(600, 12.5, anchor=tk.NE, window=newtaskbutton)
        #endtaskbutton = tk.Button(self, text='End Task', command=lambda: taskcreator())
        #endtaskbuttonn_window = c.create_window(690, 12.5, anchor=tk.NE, window=endtaskbutton)
        RunningTask = tk.Label(self, text='Running Task').place(x=10,y=75,anchor=tk.NW)

        #canvas = Canvas(self, width=60, height=60)
        #canvas.place(x=10, y=30)

def taskcreator():
    global screen
    screen = Tk()
    thelink = StringVar()
    screen.geometry('720x640')
    Label(screen, text='Enter Shoe Link').place(x=10, y=20)
    linkentry = Entry(screen, textvariable=thelink)
    linkentry.place(x=10, y=40)
    you = Button(screen, text='End Task', command=lambda: assign(thelink))
    you.pack()
    screen.mainloop()

def assign(thelink):
    link = thelink.get()

    # print(llink.get())
    print(thelink.get())

app = SeaofBTCapp()
app.mainloop()

Thanks in advance for your help!

Samuel Okasia
  • 95
  • 1
  • 6
  • Please try to reduce this code down to a [mcve]. If the question is about getting the value out of an entry, we don't need a canvas or half a dozen buttons to reproduce the problem. – Bryan Oakley May 05 '20 at 16:07
  • i done that but for some reasons the problem was resolved, so i had to make a smaller example but still include buttons – Samuel Okasia May 05 '20 at 16:19
  • Read [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/a/48045508/7414759) and [Tkinter understanding mainloop](https://stackoverflow.com/a/29158947/7414759) – stovfl May 05 '20 at 16:43
  • So, you're saying if you remove just one of those buttons, the problem remains? That seems pretty unlikely. Do we have to click on all of the buttons to reproduce the problem? – Bryan Oakley May 05 '20 at 17:29

1 Answers1

0

change assign(linkentry) and on your function assign just print(link)

rocknrold
  • 66
  • 1
  • 4
  • sad to hear that but I tried your code and works for me, maybe you have change the function parameter. you just have to change the argument passed on the calling function inside your def taskcreator() and on your assign function print the link instead – rocknrold May 05 '20 at 16:24
  • could you send me a copy of your working one please – Samuel Okasia May 05 '20 at 16:31
  • 1
    `def taskcreator(): global screen screen = Tk() thelink = StringVar() screen.geometry('720x640') Label(screen, text='Enter Shoe Link').place(x=10, y=20) linkentry = Entry(screen, textvariable=thelink) linkentry.place(x=10, y=40) you = Button(screen, text='End Task', command=lambda: assign(linkentry)) #linkentry you.pack() screen.mainloop() def assign(thelink): link = thelink.get() # print(llink.get()) print(link) #print link` – rocknrold May 05 '20 at 16:37
  • up voteeeeee plssss:DDDD hahahaha justkidding always welcome:)) – rocknrold May 05 '20 at 16:44
  • it is the up arrow on the left side of my answer, I believe it gives reputation – rocknrold May 05 '20 at 16:54