• 1400/02/17

نمایش متن نوشته شده درENTRYدرصفحهGUI :

سلام 

من میخوام چیزی که توی ENTRY نوشته میشه وبجای چاپ در ترمینال بصورت لیبل توی همون صفحه گرافیکی اضافه شه.چه کدهایی رو باید اضافه کنم؟؟

الان قسمت نوشته شده توی ترمینال نمایش داده میشه من میخوام توی همون فضای GUIنمایش داده شه

from tkinter import  *
#==============================setting======================================
root=Tk()
root.title("ENTRY")
root.geometry('300x250')
root.resizable(width=False,height=False)
#==============================setting======================================

namelable=Label(root,text='Please enter your name:')
namelable.place(x=30,y=20)

#==============================entry======================================
nameinput=Entry(root)
nameinput.place(x=35,y=50)
#==============================function======================================
def view():
    print(nameinput.get())

def show():
    x=nameinput.get()
    print(x)


#==============================buttons======================================
btn=Button(root,text='Get Name',command=view)
btn.place(x=35,y=80)

#==============================RUN======================================
root.mainloop()
  • 1400/02/19
  • ساعت 13:07

سلام

داخل فانکشن view  کد زیر را اضافه کنید

l1 = Label(root, text=nameinput.get())
l1.place(x=35, y=110)

بعد از آن با فشردن دکمه Get Name  لیبلی در صفحه ایجاد می‏‏‏ شود و مقدار موجود در nameinput را نمایش میدهد

کد نهایی :

from tkinter import *

# ==============================setting======================================
root = Tk()
root.title("ENTRY")
root.geometry('300x250')
root.resizable(width=False, height=False)
# ==============================setting======================================

namelable = Label(root, text='Please enter your name:')
namelable.place(x=30, y=20)

# ==============================entry======================================
nameinput = Entry(root)
nameinput.place(x=35, y=50)


# ==============================function======================================
def view():
    print(nameinput.get())
    l1 = Label(root, text=nameinput.get())
    l1.place(x=35, y=110)


def show():
    x = nameinput.get()
    print(x)


# ==============================buttons======================================
btn = Button(root, text='Get Name', command=view)
btn.place(x=35, y=80)


# ==============================RUN======================================
root.mainloop()