tKinter条目不打印任何内容

问题描述 投票:-1回答:1

我正在使用python中的tktinter创建一个应用程序。我创建了一个名为“新任务”的按钮,该按钮调用了一个用户可以在其中输入链接的函数,然后创建了另一个按钮,在该按钮上调用了另一个函数,用户输入的链接被打印在控制台中,但是由于某种原因,它每次都不会打印任何内容。请帮助,这是代码

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()

谢谢您的帮助!

python oop tkinter tk tkinter-entry
1个回答
0
投票

更改assign(linkentry)和在您的功能上只分配print(link)

© www.soinside.com 2019 - 2024. All rights reserved.