Home > OS >  how to take the data from an entry to a variable in python
how to take the data from an entry to a variable in python

Time:04-28

from ctypes import sizeof
import tkinter as tk
from tkinter import *
import tkinter.ttk as tkk
from turtle import width
from selenium import *
import webbrowser

new = 1

window = tk.Tk()

def Done():
   global species
   string= species.get()
   furry.configure(text=string)

furry = tk.Label(
    text="This is a furry pic generator enjoy",
    foreground="Black",
    width=60,
    height=5
)
furry.pack()

species = tk.Entry()
species.pack(fill=tk.X)

x = species.get()

url = "https://www.google.com/search?q="   species.get()

def openweb():
    webbrowser.open(url,new=new)

Furrygen = tk.Button(
    text="Get a furry",
    width=25,
    height=2,
    fg="Black",
    command=openweb
)
Furrygen.pack(fill=tk.X)

window.mainloop()

that's my code what I want is to take the data from the entry of species and add it to the search of google to open in a new tab with the search already done I have done everything but for some reason, it doesn't want to put the data from the entry on the search tag why is that?

CodePudding user response:

Adding the .get() to your openweb() function solved the issue when I tested it. Look at the print statments I added and you can see it is in fact grabbing the input. You should also reformat your script for readability and to take out redundancies.

import tkinter as tk
import tkinter.ttk as tkk
import webbrowser


new = 1

def openweb():
    value = species.get()
    species.delete("0", tk.END)
    print(value)
    url = "https://www.google.com/search?q="   value
    print(url)
    webbrowser.open(url,new=new)

    
def Done():
   global species
   string= species.get()
   furry.configure(text=string)


window = tk.Tk()

furry = tk.Label(text="This is a furry pic generator enjoy", foreground="Black",
                 width=60, height=5)
furry.pack()

species = tk.Entry()
species.pack(fill=tk.X)

Furrygen = tk.Button(text="Get a furry", width=25, height=2,
                     fg="Black", command=openweb)
Furrygen.pack(fill=tk.X)

window.mainloop()
  • Related