Python Forum
[Tkinter] Entry widget to variable - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/Forum-Python-Coding)
+--- Forum: GUI (https://python-forum.io/Forum-GUI)
+--- Thread: [Tkinter] Entry widget to variable (/Thread-Tkinter-Entry-widget-to-variable)



Entry widget to variable - Zeiphar - Sep-20-2019

Hey guys. Im a bit of a scrub when it comes to coding, specially with python. Just need some help with getting the ip/port range from the entry widgets up to their corresponding variables. this is what i have so far. And no i'm not trying to be some 1337 hakzorz i run servers at home and i like poking at my network to make sure i havnt opened something i shouldnt have or to see whats happening on my network. I havent really had much luck finding anything when googling This is what i have so far.


from tkinter import *




main = Tk()
main.title('Blackmap')
main.geometry("700x700")
main.resizable(0, 0)

# Variables
IPRange = '0.0.0.0'
PortRange = '0'

# Functions
def setiprange():
    IPRange = IPRangeEntry.get()
    print("The IP range set is:", IPRange)


def setportrange():

    print("The Port range set is:", PortRange)


# Labels
Label(main, text="Options").place(x=500, y=15)
Label(main, text="Scan Type").place(x=350, y=15)
Label(main, text="Enable").place(x=579, y=15)
Label(main, text="Disable").place(x=634, y=15)

# Buttons
SetIPbttn = Button(text="Set IP Range", fg="green", command=setiprange,  height=1, width=11).place(x=5, y=40)
SetPortRangebttn = Button(text="Set Port Range", fg="green", command=setportrange, height=1, width=11).place(x=5, y=80)

# Radio Buttons
Drb1 = Radiobutton(main).place(x=645, y=30)
Drb2 = Radiobutton(main).place(x=645, y=52)
Drb3 = Radiobutton(main).place(x=645, y=74)
Drb4 = Radiobutton(main).place(x=645, y=96)
Drb5 = Radiobutton(main).place(x=645, y=118)
Drb6 = Radiobutton(main).place(x=645, y=140)
Drb7 = Radiobutton(main).place(x=645, y=162)
Drb8 = Radiobutton(main).place(x=645, y=184)
Drb9 = Radiobutton(main).place(x=645, y=206)
Drb10 = Radiobutton(main).place(x=645, y=228)
Erb1 = Radiobutton(main).place(x=590, y=30)
Erb2 = Radiobutton(main).place(x=590, y=52)
Erb3 = Radiobutton(main).place(x=590, y=74)
Erb4 = Radiobutton(main).place(x=590, y=96)
Erb5 = Radiobutton(main).place(x=590, y=118)
Erb6 = Radiobutton(main).place(x=590, y=140)
Erb7 = Radiobutton(main).place(x=590, y=162)
Erb8 = Radiobutton(main).place(x=590, y=184)
Erb9 = Radiobutton(main).place(x=590, y=206)
Erb10 = Radiobutton(main).place(x=590, y=228)


# Entry Boxes
IPRangeEntry = Entry(main).place(x=115, y=44)
PortRangeEntry = Entry(main).place(x=115, y=84)


main.mainloop()




RE: Entry widget to variable - woooee - Sep-20-2019

IPRangeEntry = Entry(main).place(x=115, y=44)
PortRangeEntry = Entry(main).place(x=115, y=84)
place() returns None. You have to first store the Entry instance so you can access in the function.

PRangeEntry = Entry(main)
PRangeEntry.place(x=115, y=44)



RE: Entry widget to variable - Zeiphar - Sep-20-2019

(Sep-20-2019, 02:28 PM)woooee Wrote:
IPRangeEntry = Entry(main).place(x=115, y=44)
PortRangeEntry = Entry(main).place(x=115, y=84)
place() returns None. You have to first store the Entry instance so you can access in the function.

PRangeEntry = Entry(main)
PRangeEntry.place(x=115, y=44)


when changing
IPRangeEntry = Entry(main).place(x=115, y=44)
to
IPRangeEntry = Entry(main)IPRangeEntry.place(x=115, y=44)

i just get a syntax error


RE: Entry widget to variable - Yoriz - Sep-20-2019

IPRangeEntry.place(x=115, y=44)
should be on the next separate line

IPRangeEntry = Entry(main)
IPRangeEntry.place(x=115, y=44)



RE: Entry widget to variable - Zeiphar - Sep-21-2019

(Sep-20-2019, 03:20 PM)Yoriz Wrote:
IPRangeEntry.place(x=115, y=44)
should be on the next separate line

IPRangeEntry = Entry(main)
IPRangeEntry.place(x=115, y=44)

Ahh thank you. That fixed it :)