Hi, Very new to tkinter …
simple Frame with an Entry box
import sys
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.constants import *
import iptoname_support
class IPToName:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#ececec' # Closest X11 color: 'gray92'
self.style = ttk.Style()
if sys.platform == "win32":
self.style.theme_use('winnative')
self.style.configure('.',background=_bgcolor)
self.style.configure('.',foreground=_fgcolor)
self.style.map('.',background=
[('selected', _compcolor), ('active',_ana2color)])
top.geometry("774x701+557+57")
top.minsize(120, 1)
top.maxsize(3844, 2141)
top.resizable(1, 1)
top.title("IP To Name")
top.configure(background="#d9d9d9")
top.configure(highlightbackground="#d9d9d9")
top.configure(highlightcolor="black")
self.top = top
self.ip2nimport_path = tk.StringVar()
self.ip2nimportfield = tk.Entry(self.top)
self.ip2nimportfield.place(relx=0.297, rely=0.029, height=20
, relwidth=0.677)
self.ip2nimportfield.configure(background="white")
self.ip2nimportfield.configure(disabledforeground="#a3a3a3")
self.ip2nimportfield.configure(font="TkFixedFont")
self.ip2nimportfield.configure(foreground="#000000")
self.ip2nimportfield.configure(insertbackground="black")
self.ip2nimportfield.configure(textvariable=self.ip2nimport_path)
Got my functions defined in an _support.py file, I can get the filedialog box to pop and save the selection to a varaible, but I can’t seem to get the variable to pack back to the _main.py tk.Entry field no matter what I try?
import sys
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.constants import *
from tkinter.ttk import Entry
import iptoname
def main(*args):
'''Main entry point for the application.'''
global root
root = tk.Tk()
root.protocol('WM_DELETE_WINDOW', root.destroy)
# Creates a toplevel widget.
global _top1, _w1
_top1 = root
_w1 = iptoname.IPToName(_top1)
root.mainloop()
def ip2n_getimport(*args):
global ip2nimport_path
import tkinter
from tkinter import filedialog
tkinter.Tk().withdraw() # prevents an empty tkinter window from appearing
ip2nimport_path = filedialog.askopenfilename(title="Select File")
print(ip2nimport_path)
sys.stdout.flush()
python 3.10 …
I’ve tried so many combinations of gluing the variable to the function.Entry path I’m all mixed up.
Any pointers are appreciated , downloading grayson’s book on Tkinter to start reading …
Thanks