0

Hello I am trying to get information from input fields and trying to print giris.get() ,but ı cant access this one where is the problem ? I searched a lot in stackoverflow ,but none of them solved my problem

 from selenium import webdriver
from tkinter import *



root = Tk()
root.geometry("500x400")
root.title("Spotify Ortak Sarkilar")


giris = Entry(root,width = 50,
bg = "black",
fg = "white",
 )

giris2 = Entry(root,width = 50,
bg = "black",
fg = "white",
)
giris3 = Entry(root,width = 50,
bg = "black",
fg = "white",
)
get1 = ""
get2 = ""
x = ""
def myclick():
  global x
  x = (giris.get())
  y = (giris2.get())
  root.destroy()

giris.pack(padx= 50,pady = 20)
giris2.pack(padx= 50,pady = 10)
giris.insert(0,"1.Spotify Linkini giriniz.")
giris2.insert(0,"2.Spotify Linkini giriniz.")

buton = Button(root,text ="Yolla", command =lambda: myclick , fg = "white"  ,bg = "black" ,padx= 50)
buton.pack(pady = 100)
print(x)

root.mainloop()

2 Answers2

0

myClick isn't being executed, to fix that don't use lambda.

buton = Button(root,text ="Yolla", command =myclick , fg = "white"  ,bg = "black" ,padx= 50)
norie
  • 9,609
  • 2
  • 11
  • 18
  • How is it not working? If I add code to print x and y to the myclick function the appropriate values are printed to the console when the button is clicked. – norie Mar 06 '21 at 12:00
  • But ı want to access this x out of the def function,I can print in def function but that is not ı want – Mustafa Kendigüzel Mar 06 '21 at 13:14
  • Why are you destroying root when the button us clucked? That will stop all code execution. – norie Mar 06 '21 at 13:45
  • Nothing will change if ı deleted this part – Mustafa Kendigüzel Mar 06 '21 at 15:18
  • Delete which part. Can you explain what you actually want to do? – norie Mar 06 '21 at 15:46
  • from tkinter import * root = Tk() root.geometry("500x400") root.title("Spotify Ortak Sarkilar") giris = Entry(root,width = 50, bg = "black", fg = "white", ) giris.pack(pady = 30) bos = [] def tiklama(): bos.append(giris.get()) buton = Button(root,text = "Tikla",command = tiklama ) buton.pack(pady= 30) print(bos) root.mainloop() – Mustafa Kendigüzel Mar 06 '21 at 16:23
  • I wanna access the bos array update this every time but ı cant access the bos array – Mustafa Kendigüzel Mar 06 '21 at 16:24
  • There's no array in the original code, and don't post code in comments - it's unreadable and unformatted. If something has changed edit the original question. – norie Mar 06 '21 at 16:41
0

I am trying to get information from input fields and trying to print giris.get() ,but ı cant access this one where is the problem.

The problem can be fixed.

Add print() on myclick() function.

code:

def myclick():  
  x = (giris.get())
  y = (giris2.get())
  print(x)
  print(y)
  root.destroy()

Output:

1.Spotify Linkini giriniz.deepika padukone
2.Spotify Linkini giriniz.Wallis Day
toyota Supra
  • 3,181
  • 4
  • 15
  • 19