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()
Related
Was finally able to get images to display properly in my .py file, with correct sizing and whatnot. Now, my issue is that they don't display at all after compiling with pyinstaller.
The images show up in the temp directory and I can navigate to it and open them.
The program will correctly print the location of the images.
The program will correctly print the images' information like dimensions
I'm not sure what I'm doing wrong.
Traceback:
Traceback (most recent call last):
File "tkinter\__init__.py", line 1921, in __call__
File "Tools\Cable_Resistance_Calculator\cable_resistance_calculator.py",
line 109, in max_power
File "customtkinter\windows\widgets\ctk_label.py",
line 93, in __init__
self._update_image()
File "customtkinter\windows\widgets\ctk_label.py",
line 130, in _update_image
self._label.configure(image=self._image.create_scaled_photo_image(self._get_widget_scaling(), File "tkinter\__init__.py",
line 1675, in configure
File "tkinter\__init__.py",
line 1665, in _configure _tkinter.TclError: image "pyimage1" doesn't exist
Code:
import sys, os
import customtkinter as tk
import tkinter.ttk as ttk
#
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.dirname(os.path.realpath(__file__))
return os.path.join(base_path, relative_path)
#
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 vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.CTk()
top = crc_main_window (root)
init(root, top)
root.mainloop()
#
w = None
def create_crc_main_window(rt, *args, **kwargs):
global w, w_win, root
root = rt
w = tk.CTkToplevel (root)
top = crc_main_window (w)
init(w, top, *args, **kwargs)
return (w, top)
#
def destroy_crc_main_window():
global w
w.destroy()
w = None
#
class crc_main_window:
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'
# setting geometry and locking it in, as well as the title
top.geometry("392x300+607+367")
top.minsize(120, 1)
top.maxsize(3604, 1061)
top.resizable(0, 0)
top.title("Cable Resistance Calculator")
top.configure(background="#d9d9d9")
#
def max_power():
#
self.max_power_top = tk.CTkToplevel(root)
#
self.max_power_top.title("Max Power Transmission")
#
self.max_power_top.geometry("592x313+607+367")
self.max_power_top.resizable(0, 0)
#
self.max_frame = tk.CTkFrame(self.max_power_top)
#
self.max_frame.place(x=3,y=3,width=586,height=307)
#
from PIL import ImageTk, Image
self.image1 = Image.open(resource_path('max_power_trans.PNG'))
self.image = tk.CTkImage(self.image1, size=(580,301))
self.label1 = tk.CTkLabel(master=self.max_frame,image=self.image)
self.label1.image=self.image
self.label1.place(x=3,y=3,width=583,height=304)
self.label1.configure(text="")
def power_calc():
self.power_calc_top = tk.CTkToplevel(root)
self.power_calc_top.title("Power Calculation Reference")
self.power_calc_top.geometry("922x481+607+367")
self.power_calc_top.resizable(0, 0)
#
self.power_frame = tk.CTkFrame(self.power_calc_top)
self.power_frame.place(x=3,y=3,width=916,height=475)
#
from PIL import ImageTk, Image
self.image2 = Image.open(resource_path('power_calc.png'))
self.image3 = tk.CTkImage(self.image2, size=(910,469))
self.label2 = tk.CTkLabel(self.power_frame,image=self.image3)
self.label2.image=self.image3
self.label2.place(x=3,y=3,width=913,height=472)
self.label2.configure(text="")
#
from tkinter import Menu
menubar = Menu(top)
top.config(menu=menubar)
file_menu = Menu(menubar,tearoff=False)
file_menu.add_command(label='Max Power Reference',command=max_power)
file_menu.add_command(label='Power Calc Reference',command=power_calc)
file_menu.add_command(label='Exit',command=root.destroy)
menubar.add_cascade(label="File",menu=file_menu,underline=0)
if __name__ == '__main__':
vp_start_gui()
Compiler code:
import PyInstaller.__main__ as pym
pym.run([
'main_hub.py',
'--onefile',
'--console',
'--noconfirm',
'--add-data=compile\\lib\\site-packages\\customtkinter\\;customtkinter\\',
'--add-data=Tools\\Cable_Resistance_Calculator\\max_power_trans.PNG;.',
'--add-data=Tools\\Cable_Resistance_Calculator\\power_calc.png;.',
])
Update: I've also tried in --onedir mode, and with a hardcoded path to the image files. Neither have worked so far.
So I took my minimum reproducer code and created a new .py file with it, and tested it to find it worked perfectly fine. So what gives?
Well, as it turns out...I did in fact have another CTk() window. This script is part of a larger program that had already called root = tk.CTk(), so I already had an existing root window. I changed up the way the main program calls this script, and now it works.
I want to show a message(popup) while python script is executing and automatically disapper when the script done exectuing
import sys
from tkinter import ttk
from tkinter import messagebox
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 new_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
top = Toplevel1 (root)
new_support.init(root, top)
root.mainloop()
w = None
def create_Toplevel1(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = tk.Toplevel (root)
top = Toplevel1 (w)
new_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Toplevel1():
global w
w.destroy()
w = None
class Toplevel1:
def smsdata(self):
MsgBox = tk.messagebox.showinfo('Analysing', 'Please wait till the data is being analysed')
* My Script*
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("534x226+710+62")
top.minsize(1, 1)
top.maxsize(1905, 898)
top.resizable(1, 1)
top.title("SMS_Analysis")
top.configure(highlightbackground="#00d81d")
self.Frame1 = tk.Frame(top)
self.Frame1.place(relx=0.0, rely=0.0, relheight=0.996, relwidth=1.002)
self.Frame1.configure(relief='ridge')
self.Frame1.configure(borderwidth="2")
self.Frame1.configure(relief="ridge")
self.Frame1.configure(background="#180bd8")
self.Execute = tk.Button(self.Frame1)
self.Execute.place(relx=0.093, rely=0.089, height=104, width=436)
self.Execute.configure(activebackground="#10ed00")
self.Execute.configure(activeforeground="#ffffff")
self.Execute.configure(background="#10d802")
self.Execute.configure(relief="groove")
self.Execute.configure(text='''Execute''')
self.Execute.configure(command=self.smsdata);
self.Message1 = tk.Message(self.Frame1)
self.Message1.place(relx=0.224, rely=0.756, relheight=0.133
, relwidth=0.563)
self.Message1.configure(text='''Wait For 2 Min''')
self.Message1.configure(width=301)
self.TProgressbar1 = ttk.Progressbar(self.Frame1)
self.TProgressbar1.place(relx=0.093, rely=0.578, relwidth=0.804
, relheight=0.0, height=19)
self.TProgressbar1.configure(length="430")
if __name__ == '__main__':
vp_start_gui()
I want to display Popup While following code is running
def smsdata(self):
MsgBox = tk.messagebox.showinfo('Analysing', 'Please wait till the data is being analysed')
* My Script*
After execution of the popup should disappear.
I have created a MsgBox but the issue is when I press "OK" then script starts executing. I want the popup to appear when code is being executed and vanish when complete executing
new_support
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
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
if __name__ == '__main__':
import new
new.vp_start_gui()
You can use multithreading module or thread module if you want to process multiple commands at the same time if this is the answer that you are searching for.
i am tying to live stream camera in label using tkinter with opencv and python2 but problem is when i click on button only one frame display in label.
#! /usr/bin/env python
# -- coding: utf-8 --
#
# GUI module generated by PAGE version 4.22
# in conjunction with Tcl version 8.6
# May 17, 2019 06:44:40 PM PKT platform: Linux
.
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 gui_support
from Tkinter import *
from PIL import ImageTk, Image
import cv2
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
top = Toplevel1 (root)
gui_support.init(root, top)
root.mainloop()
w = None
def create_Toplevel1(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = tk.Toplevel (root)
top = Toplevel1 (w)
gui_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Toplevel1():
global w
w.destroy()
w = None
class Toplevel1:
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("1308x647+69+51")
top.title("New Toplevel")
self.menubar = tk.Menu(top,font="TkMenuFont",bg=_bgcolor,fg=_fgcolor)
top.configure(menu = self.menubar)
self.Label1 = tk.Label(top)
self.Label1.place(relx=0.268, rely=0.015, height=31, width=599)
self.Label1.configure(font="-family {Bitstream Vera Sans} -size 21 -weight bold")
self.Label1.configure(text='''Face ID Attendance Marking System''')
self.Label1.configure(width=599)
self.TSeparator1 = ttk.Separator(top)
self.TSeparator1.place(relx=0.245, rely=0.077, relwidth=0.497)
self.TPanedwindow1 = ttk.Panedwindow(top, orient="horizontal")
self.TPanedwindow1.place(relx=0.008, rely=0.139, relheight=0.68
, relwidth=0.982)
self.TPanedwindow1.configure(width=1285)
self.TPanedwindow1_p1 = ttk.Labelframe(width=650, text='Pane 1')
self.TPanedwindow1.add(self.TPanedwindow1_p1)
self.TPanedwindow1_p2 = ttk.Labelframe(text='Pane 2')
self.TPanedwindow1.add(self.TPanedwindow1_p2)
self.__funcid0 = self.TPanedwindow1.bind('<Map>', self.__adjust_sash0)
self.Label2 = tk.Label(self.TPanedwindow1_p1)
self.Label2.place(relx=0.016, rely=0.045, height=411, width=619
, bordermode='ignore')
self.Label2.configure(text='''Label''')
self.Label2.configure(width=619)
self.TButton1 = ttk.Button(top)
self.TButton1.place(relx=0.031, rely=0.835, height=28, width=83)
self.TButton1.configure(takefocus="")
self.TButton1.configure(text='''Tbutton''')
self.TButton1.configure(command = self.cameratk)
def __adjust_sash0(self, event):
paned = event.widget
pos = [640, ]
i = 0
for sash in pos:
paned.sashpos(i, sash)
i += 1
paned.unbind('<map>', self.__funcid0)
del self.__funcid0
def cameratk(self):
cap = cv2.VideoCapture(0)
_, frame = cap.read()
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img)
self.Label2.imgtk = imgtk
self.Label2.configure(image=imgtk)
self.Label2.after(1, video_stream)
if __name__ == '__main__':
vp_start_gui()
Solved
self.Label2.after(1, video_stream)
Video_Stream Replaced by Function name as self.cameratk
self.Label2.after(1, self.cameratk)
and cap = cv2.VideoCapture(0) outside from the function.
I'm just adding 1 def with 2 lines of code before it gets indentation error. I'm trying to modify the code that generated from PAGE Tkinter GUI editor for login message box. I really don't know why this happens.
I did the exact same code as this guy on youtube and I tried to move the def into the far-most left neither right.
So what I'm trying to add is. def cancelLogin() inside the login page class. It shows me indentation error on def init(). Please help me to figure this out.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.20
# in conjunction with Tcl version 8.6
# Feb 07, 2019 05:38:55 AM EST platform: Linux
import sys
import tkMessageBox
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 jta_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
top = Login_page (root)
jta_support.init(root, top)
root.mainloop()
w = None
def create_Login_page(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = tk.Toplevel (root)
top = Login_page (w)
jta_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Login_page():
global w
w.destroy()
w = None
class Login_page:
def cancelLogin(self):
msg=tkMessageBox.askyesno("Login page","Are you sure , you want to cancel login?")
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'
font11 = "-family {DejaVu Sans} -size 10 -weight bold -slant " \
"roman -underline 0 -overstrike 0"
font17 = "-family {DejaVu Sans} -size 13 -weight bold -slant " \
"roman -underline 0 -overstrike 0"
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("584x457+1039+55")
top.title("JTA Login")
top.configure(relief="ridge")
top.configure(background="#201856")
top.configure(highlightbackground="#000000")
self.btnLogin = tk.Button(top)
self.btnLogin.place(relx=0.634, rely=0.744, height=54, width=101)
self.btnLogin.configure(background="#201856")
self.btnLogin.configure(borderwidth="0")
self.btnLogin.configure(font=font11)
self.btnLogin.configure(highlightbackground="#201856")
self._img1 = tk.PhotoImage(file="../../Downloads/button.png")
self.btnLogin.configure(image=self._img1)
self.btnLogin.configure(padx="6m")
self.btnLogin.configure(pady="3m")
self.btnLogin.configure(text='''Login''')
self.btnLogin.configure(width=101)
self.btnExit = tk.Button(top)
self.btnExit.place(relx=0.223, rely=0.744, height=55, width=97)
self.btnExit.configure(activebackground="#ffffff")
self.btnExit.configure(background="#201856")
self.btnExit.configure(borderwidth="0")
self.btnExit.configure(font=font11)
self.btnExit.configure(highlightbackground="#201856")
self._img2 = tk.PhotoImage(file="../../Downloads/button(1).png")
self.btnExit.configure(image=self._img2)
self.btnExit.configure(padx="6m")
self.btnExit.configure(pady="3m")
self.btnExit.configure(text='''Exit''')
self.btnExit.configure(width=97)
self.txtUsername = tk.Entry(top)
self.txtUsername.place(relx=0.462, rely=0.372, height=40, relwidth=0.342)
self.txtUsername.configure(background="white")
self.txtUsername.configure(font="TkFixedFont")
self.txtPassword = tk.Entry(top)
self.txtPassword.place(relx=0.462, rely=0.547, height=40, relwidth=0.342)
self.txtPassword.configure(background="white")
self.txtPassword.configure(font="TkFixedFont")
self.txtPassword.configure(selectbackground="#c4c4c4")
self.Label1 = tk.Label(top)
self.Label1.place(relx=0.205, rely=0.372, height=40, width=100)
self.Label1.configure(background="#201856")
self.Label1.configure(font=font17)
self.Label1.configure(foreground="#ffffff")
self.Label1.configure(text='''Username''')
self.Label1_3 = tk.Label(top)
self.Label1_3.place(relx=0.205, rely=0.547, height=40, width=100)
self.Label1_3.configure(activebackground="#f9f9f9")
self.Label1_3.configure(background="#201856")
self.Label1_3.configure(font=font17)
self.Label1_3.configure(foreground="#ffffff")
self.Label1_3.configure(text='''Password''')
self.menubar = tk.Menu(top,font="TkMenuFont",bg=_bgcolor,fg=_fgcolor)
top.configure(menu = self.menubar)
self.TLabel1 = ttk.Label(top)
self.TLabel1.place(relx=0.154, rely=0.022, height=131, width=423)
self.TLabel1.configure(background="#201856")
self.TLabel1.configure(foreground="#000000")
self.TLabel1.configure(font="TkDefaultFont")
self.TLabel1.configure(relief='flat')
self.TLabel1.configure(text='''Tlabel''')
self.TLabel1.configure(width=423)
self._img3 = tk.PhotoImage(file="./jtalogo.png")
self.TLabel1.configure(image=self._img3)
if __name__ == '__main__':
vp_start_gui()
without the "def cancelLogin()" it works fine as usual
actual result :
File "./jta.py", line 52
def init(self, top=None):
^
IndentationError: unindent does not match any outer indentation level
You can try:
grep -C 7 "__init" YOUR_FILE.py | tr ' \t' '.*'
This will translate spaces into dots, and tabs into stars. Then you can check if there is a mismatch there.
This is the output when I tried it on the code you posted (from the question source):
$ grep -C 7 "__init" test.py | tr ' \t' '.*'
........w.=.None
....
....class.Login_page:
....
....*def.cancelLogin(self):
....**msg=tkMessageBox.askyesno("Login.page","Are.you.sure.,.you.want.to.cancel.login?")
....
........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'.
As stated by #tobias_k, there are tabs and spaces mixed in the lines you added.
I am using tkinter and i have 2 .py files, one called "account" and another called "account_support" im trying to build the gui in the "account.py" and then have all the functions related to that gui in "account_support.py"
this is account.py
import sys
try:
from Tkinter import *
except ImportError:
from tkinter import *
try:
import ttk
py3 = 0
except ImportError:
import tkinter.ttk as ttk
py3 = 1
import account_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = Tk()
top = Add_Account (root)
account_support.init(root, top)
root.mainloop()
w = None
def create_Add_Account(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = Toplevel (root)
top = Add_Account (w)
account_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Add_Account():
global w
w.destroy()
w = None
class Add_Account:
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 = '#d9d9d9' # X11 color: 'gray85'
font9 = "-family {DejaVu Sans} -size 0 -weight normal -slant " \
"roman -underline 0 -overstrike 0"
top.geometry("400x200+407+266")
top.title("Add Account")
top.configure(highlightcolor="black")
self.menubar = Menu(top,font=font9,bg=_bgcolor,fg=_fgcolor)
top.configure(menu = self.menubar)
self.accName = Entry(top)
self.accName.place(relx=0.35, rely=0.3, relheight=0.11, relwidth=0.44)
self.accName.configure(background="white")
self.accName.configure(font="TkFixedFont")
self.accName.configure(selectbackground="#c4c4c4")
self.Label1 = Label(top)
self.Label1.place(relx=0.25, rely=0.1, height=38, width=176)
self.Label1.configure(activebackground="#f9f9f9")
self.Label1.configure(text='''Add Account''')
self.Label2 = Label(top)
self.Label2.place(relx=0.03, rely=0.3, height=18, width=126)
self.Label2.configure(activebackground="#f9f9f9")
self.Label2.configure(text='''Account Name:''')
self.key = Entry(top)
self.key.place(relx=0.35, rely=0.5, relheight=0.11, relwidth=0.44)
self.key.configure(background="white")
self.key.configure(font="TkFixedFont")
self.key.configure(selectbackground="#c4c4c4")
self.Label3 = Label(top)
self.Label3.place(relx=0.15, rely=0.5, height=21, width=76)
self.Label3.configure(activebackground="#f9f9f9")
self.Label3.configure(text='''CMA Key:''')
self.add = Button(top)
self.add.place(relx=0.53, rely=0.7, height=26, width=107)
self.add.configure(activebackground="#d9d9d9")
self.add.configure(command=account_support.addaccount)
self.add.configure(text='''Add Account''')
self.helpButton = Button(top)
self.helpButton.place(relx=0.8, rely=0.5, height=16, width=17)
self.helpButton.configure(activebackground="#d9d9d9")
self.helpButton.configure(command=account_support.question)
self.helpButton.configure(text='''?''')
if __name__ == '__main__':
vp_start_gui()
and then for account_support.py
import sys
import webbrowser
import tkMessageBox
try:
from Tkinter import *
except ImportError:
from tkinter import *
try:
import ttk
py3 = 0
except ImportError:
import tkinter.ttk as ttk
py3 = 1
def addaccount():
import account
cmakey = account.Entry.key.get()
acc = account.Entry.accName.get()
print acc
print cmakey
sys.stdout.flush()
def question():
tkMessageBox.showinfo(title="CMA Key", message="")
sys.stdout.flush()
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
if __name__ == '__main__':
import account
account.vp_start_gui()
when i try to get the value of account.py's key entry
with
def addaccount():
import account
cmakey = account.Entry.key.get()
acc = account.Entry.accName.get()
print acc
print cmakey
sys.stdout.flush()
i get the error
File "/home/silicaandpina/VitaTools/psvimgtools-0.1-linux64/gui/psvimgtools/account_support.py", line 29, in addaccount
cmakey = account.Entry.key.get()
AttributeError: class Entry has no attribute 'key'
When you're executing
cmakey = account.Entry.key.get()
acc = account.Entry.accName.get()
you're trying to access the key property of the Entry class of Tkinter in your module account. As you can tell by the error message, the Entry class doesn't have a property called key.
The Solution
Change your addaccount function to
def addaccount(cmakey, acc):
print acc
print cmakey
sys.stdout.flush()
As you can see, you're now receiving two parameters that are already the strings you want to use. Now, in account, change the button configuration line to
self.add.configure(command=lambda: account_support.addaccount(self.key.get(), self.accName.get()))