Hello I've set up a GUI for my Python Pinger but somehow I'm unable to change label placed inside the Main Class of the program.
Here is the main script:
import sys
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
import PyngIT_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
top = PythonPingIT (root)
PyngIT_support.init(root, top)
root.mainloop()
w = None
def create_PythonPingIT(rt, *args, **kwargs):
'''Starting point when module is imported by another module.
Correct form of call: 'create_PythonPingIT(root, *args, **kwargs)' .'''
global w, w_win, root
#rt = root
root = rt
w = tk.Toplevel (root)
top = PythonPingIT (w)
PyngIT_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_PythonPingIT():
global w
w.destroy()
w = None
class PythonPingIT:
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.configure('.',font="TkDefaultFont")
self.style.map('.',background=
[('selected', _compcolor), ('active',_ana2color)])
top.geometry("1200x800+373+87")
top.minsize(176, 1)
top.maxsize(1924, 1050)
top.resizable(1, 1)
top.title("PyngIT")
top.configure(background="#e4e4e4")
top.configure(highlightbackground="#d9d9d9")
top.configure(highlightcolor="black")
self.Frame_StaniceA = tk.LabelFrame(top)
self.Frame_StaniceA.place(relx=0.006, rely=0.0, relheight=0.331
, relwidth=0.985)
self.Frame_StaniceA.configure(relief='groove')
self.Frame_StaniceA.configure(foreground="black")
self.Frame_StaniceA.configure(text='''Stanice A''')
self.Frame_StaniceA.configure(background="#d9d9d9")
self.Frame_StaniceA.configure(highlightbackground="#d9d9d9")
self.Frame_StaniceA.configure(highlightcolor="black")
self.Motol = tk.Label(self.Frame_StaniceA)
self.Motol.place(relx=0.007, rely=0.083, height=31, width=95
, bordermode='ignore')
self.Motol.configure(activebackground="#f9f9f9")
self.Motol.configure(activeforeground="black")
self.Motol.configure(background="#d9d9d9")
self.Motol.configure(disabledforeground="#a3a3a3")
self.Motol.configure(foreground="#000000")
self.Motol.configure(highlightbackground="#d9d9d9")
self.Motol.configure(highlightcolor="black")
self.Motol.configure(text='''N. Motol''')
if __name__ == '__main__':
vp_start_gui()
And here is the support script:
import sys
import multiping
import os
from threading import Thread
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
def init(top, gui, *args, **kwargs):
global w, top_level, root
w = gui
top_level = top
root = top
def destroy_window():
# Function which closes the window.
global top_level
top_level.destroy()
top_level = None
def ping_a_comm():
t = Thread(target=ping_A)
t.start()
pass
def ping_A():
import PyngIT as p
os.system("ping 192.168.0.1")
p.PythonPingIT.Motol.configure(text="TEXT")
pass
if __name__ == '__main__':
import PyngIT
PyngIT.vp_start_gui()
When I try to change the label I get "type object 'PythonPingIT' has no attribute 'Motol'
".
So I thought that maybe I need to call the class like this:
p.PythonPingIT().Motol.configure(text="text")
but only got this
Exception has occurred: AttributeError
'NoneType' object has no attribute 'geometry'
File "C:\Users\admin\Desktop\PythonPingIt\PyngIT.py", line 67, in __init__
top.geometry("1200x800+373+87")
File "C:\Users\admin\Desktop\PythonPingIt\PyngIT_support.py", line 45, in ping_A
p.PythonPingIT().Motol.configure(text="hey")
I am really lost and if anyone knows how to solve this, I would be really grateful
EDIT:// I managed to access the value with this code:
def ping_A():
global w, top_level, root
import PyngIT as p
root = tk.Tk()
w = p.PythonPingIT (root)
os.system("ping localhost")
w.Motol.configure(text="FUUUu")
pass
But I still am unable to change the text, even with w.Motol.pack()
or w.update()