I have this code here:
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
class Root(Tk):
def __init__(self):
super(Root, self).__init__()
self.title("Python Tkinter Dialog Widget")
self.minsize(640, 400)
self.labelFrame = ttk.LabelFrame(self, text = "Open File")
self.labelFrame.grid(column = 0, row = 1, padx = 20, pady = 20)
self.button()
def button(self):
self.button = ttk.Button(self.labelFrame, text = "Browse A File",command = self.fileDialog)
self.button.grid(column = 1, row = 1)
def fileDialog(self):
self.filename = filedialog.askopenfilename(initialdir = "/", title = "Select A File", filetype =
(("jpeg files","*.jpg"),("all files","*.*")) )
self.label = ttk.Label(self.labelFrame, text = "")
self.label.grid(column = 1, row = 2)
self.label.configure(text = self.filename)
root = Root()
root.mainloop()
I am trying to display the image I have chosen in browsing menu.
Currently I have self.label.configure(text = self.filename) to give me return filename, but how can I display the image itself?
Maybe this is what you're looking for:
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from PIL import Image, ImageTk
class Root(Tk):
def __init__(self):
super(Root, self).__init__()
self.title("Python Tkinter Dialog Widget")
self.minsize(640, 400)
self.labelFrame = ttk.LabelFrame(self, text = "Open File")
self.labelFrame.grid(column = 0, row = 1, padx = 20, pady = 20)
self.button()
def button(self):
self.button = ttk.Button(self.labelFrame, text = "Browse A File",command = self.fileDialog)
self.button.grid(column = 1, row = 1)
def fileDialog(self):
self.filename = filedialog.askopenfilename(initialdir = "/", title = "Select A File", filetype =
(("jpeg files","*.jpg"),("all files","*.*")) )
self.label = ttk.Label(self.labelFrame, text = "")
self.label.grid(column = 1, row = 2)
self.label.configure(text = self.filename)
img = Image.open(self.filename)
photo = ImageTk.PhotoImage(img)
self.label2 = Label(image=photo)
self.label2.image = photo
self.label2.grid(column=3, row=4)
root = Root()
root.mainloop()
Related
I have a problem, this is the code that opens the GeoTiff mini photo gallery window but the scrolling does not work for me. What is wrong in the code? I have the impression that the rewind and the photos are two separate things, I don't know how to "glue" them together. Thank you very much for your help.
import tkinter as tk
import glob
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import rasterio as rio
from rasterio.plot import show
SIZE_X = 100
SIZE_Y = 100
class Icon:
def __init__(self, root):
self.root = root
self.ybar = tk.Scrollbar(self.root)
self.item_canvas = tk.Canvas(self.root, width=354, height=401,
yscrollcommand=self.ybar.set)
self.ybar.configure(command=self.item_canvas.yview)
self.item_canvas.configure(scrollregion=(0, 0, 1000, 1000))
self.item_canvas.configure(background='#d8d8d9')
self.ybar.pack(side=tk.RIGHT, fill=tk.Y)
self.item_canvas.pack(side=tk.LEFT, expand=tk.TRUE, fill=tk.BOTH)
self.get_icons()
def get_dir(self):
link = r'work_dir/*.txt'
with open(link) as f:
self.file_photo = f.read()
self.link_to_dir = glob.glob(self.file_photo.rsplit('/', 1)[0] + '/*.tif')
self.number = len(self.link_to_dir)
def get_icons(self):
'''Method to add a mini gallery'''
self.get_dir()
FIGSIZE = 2.5
self.counter = -1
if self.number <= 2:
for i in range(0, self.number):
self.fig = Figure(figsize=(FIGSIZE, FIGSIZE), dpi=60)
self.canvasGeo = FigureCanvasTkAgg(self.fig, self.root)
self.canvasGeo.get_tk_widget().place(x=i * 220, y=10)
with rio.open(self.link_to_dir[i]) as src_plot:
show(src_plot, ax=self.fig.add_subplot())
self.canvasGeo.draw()
elif self.number > 2:
k = int()
y = []
for i in range(0, self.number):
if i % 2 == 0:
k = i
y.append(k)
for j in range(0, self.number):
self.counter += 1
if (j * 220) <= 220:
self.fig = Figure(figsize=(FIGSIZE, FIGSIZE), dpi=60)
self.canvasGeo = FigureCanvasTkAgg(self.fig, self.root)
self.canvasGeo.get_tk_widget().place(x=10 + j * 190, y=10)
with rio.open(self.link_to_dir[y[j]]) as src_plot:
show(src_plot, ax=self.fig.add_subplot())
self.canvasGeo.draw()
else:
self.fig = Figure(figsize=(FIGSIZE, FIGSIZE), dpi=60)
self.canvasGeo = FigureCanvasTkAgg(self.fig, self.root)
self.canvasGeo.get_tk_widget().place(x=(-175 * y[j]) + j * 180, y=85*y[j])
with rio.open(self.link_to_dir[y[j]]) as src_plot:
show(src_plot, ax=self.fig.add_subplot())
self.canvasGeo.draw()
else:
tk.Label(self.root, text='Wrong Value').place(x=220, y=10)
if __name__ == '__main__':
root = tk.Tk()
Icon(root)
root.mainloop()
New code:
from tkinter import *
from tkinter import filedialog
from PIL import Image, ImageTk
class Icon(Frame):
def __init__(self, master=None):
super().__init__(master)
self.pack()
self.create_widgets()
def create_widgets(self):
self.select_images_button = Button(self)
self.select_images_button["text"] = "Select Images"
self.select_images_button["command"] = self.select_images
self.select_images_button.pack()
self.quit = Button(self, text="QUIT", fg="red",
command=self.master.destroy)
self.quit.pack()
self.images_label = Label(self)
self.images_label.pack()
self.scale = Scale(self, from_=0, to=100, orient=HORIZONTAL,
command=self.resize_image)
self.scale.set(100)
self.scale.pack()
def select_images(self):
self.files = filedialog.askopenfilenames(initialdir = "/", title = "Select file",
filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
self.load_image()
def load_image(self):
self.image = Image.open(self.files[0])
self.resized_image = self.image.resize((100, 100), Image.ANTIALIAS)
self.photo = ImageTk.PhotoImage(self.resized_image)
self.images_label.configure(image=self.photo)
self.images_label.image = self.photo
def resize_image(self, value):
size = int(value)
self.resized_image = self.image.resize((size, size), Image.ANTIALIAS)
self.photo = ImageTk.PhotoImage(self.resized_image)
self.images_label.configure(image=self.photo)
self.images_label.image = self.photo
root = Tk()
app = Icon(master=root)
app.mainloop()
I want to navigate to different pages of the GUI and on some pages, I need a timer if the timer expires then it will automatically redirect the user to Startpage. or if the user navigate then also timer will stop and the user will land on another page. The problem is that the timer of other pages is running in background and randomly takes user to start page. I am not able to figure out how to solve this
The code I developed is as follows:
import os
from itertools import cycle
import PIL.ImageTk, PIL.Image
import tkinter.font as font
import tkinter as tk
from tkinter import ttk
from tkinter.ttk import *
from tkinter import *
from tkinter import messagebox
import time
from time import sleep
from threading import Thread
LARGEFONT = ("Roboto", 35)
directory = r"C:\Users\mojave\tkinter\bg_images"
images = []
for filename in os.listdir(directory):
if filename.endswith(".jpg"):
images.append(os.path.join(directory,filename))
else:
continue
print(images)
#images = ["bg1.jpg", "bg2.jpg", "bg3.jpg"]
photos = cycle(PIL.ImageTk.PhotoImage(file=image) for image in images)
class tkinterApp(tk.Tk):
def __init__(self,*args,**kwargs):
tk.Tk.__init__(self,*args,**kwargs)
container = tk.Frame(self)
container.pack(side = "top", fill = "both", expand = True)
container.grid_rowconfigure(0,weight = 1)
container.grid_columnconfigure(0,weight = 1)
self.geometry('%dx%d' % (1366, 768))
self.frames = {}
for F in (StartPage, Page1, Page2):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0,column = 0, sticky = "nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
frame.event_generate("<<ShowFrame>>")
def get_page(self, page_class):
return self.frames[page_class]
# 1 second(s)
class StartPage(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
self.photo = PhotoImage(file = r"recycle_icon.png")
self.photoimage = self.photo.subsample(20,20)
btnFont = font.Font(family='Roboto',size=32,weight='bold')
#app.geometry('%dx%d' % (1366, 768))
global displayCanvas
displayCanvas = ttk.Label(self)
displayCanvas.place(x=0,y=0)
self.after(10,lambda: slideShow())
label = ttk.Label(self,text="StartPage", font=LARGEFONT)
label.grid(row=0, column=4, padx=10, pady=10)
button1 = ttk.Button(self,text="Page 1", command=lambda: controller.show_frame(Page1))
button1.grid(row=1, column=1, padx=10, pady=10)
button2 = ttk.Button(self, text = "page 2",
command = lambda : controller.show_frame(Page2))
button2.grid(row = 2, column = 1,padx = 10,pady = 10)
start_btn = tk.Button(self,text="\nStart Recycle",height=650, width=300,image=self.photoimage,
compound= TOP, command=lambda: controller.show_frame(Page1), activebackground="green", background="red", foreground="white", bd=5)
start_btn['font'] = btnFont
#start_btn.pack(side=TOP)
start_btn.place(x=1010,y=60)
self.bind("<<ShowFrame>>", self.on_show_frame)
def on_show_frame(self,event):
print("start page is shown..")
class Page1(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
#label = ttk.Label(self, text = "Page 1", font = LARGEFONT)
#label.grid(row = 0,column = 4,padx = 10,pady = 10)
lang_btnFont = font.Font(family='Roboto',size=32,weight='bold')
self.photo = PhotoImage(file = r"recycle_icon.png")
self.photoimage = self.photo.subsample(20,20)
self.img1 = PIL.ImageTk.PhotoImage(file=r'C:\\Users\\mojave\\tkinter\\bg_image.jpg')
displayCanvas1 = ttk.Label(self)
displayCanvas1.config(image=self.img1)
displayCanvas1.place(x=0,y=0)
lang_btn = tk.Button(self,text="English",height=300,
width=300,image=self.photoimage,compound=TOP, command= lambda : controller.show_frame(Page2),
activebackground= "green",background="red",foreground="white")
lang_btn['font'] = lang_btnFont
lang_btn.place(x=1010,y=60)
lang_btn2 = tk.Button(self,text="हिन्दी",height=300, width=300,image=self.photoimage,compound=TOP,
command= lambda : controller.show_frame(Page2), activebackground=
"green",background="red",foreground="white")
lang_btn2['font'] = lang_btnFont
lang_btn2.place(x=1010,y=400)
button1 = ttk.Button(self, text ="StartPage",image=self.photoimage,command= lambda :
controller.show_frame(StartPage))
button1.grid(row = 1, column = 1,padx = 10,pady = 10)
button2 = ttk.Button(self,text = "Page 2", command = lambda : controller.show_frame(Page2))
button2.grid(row = 2, column = 1,padx = 10,pady = 10)
self.timer_label1 = tk.Label(self,font = LARGEFONT, text="10s")
self.timer_label1.place(x=2,y=200)
self.timer_thread = Thread(target = self.on_show_frame)
self.timer_thread.start()
self.after(100,self.on_show_frame)
self.bind("<<ShowFrame>>", self.on_show_frame)
def on_show_frame(self,event=None):
print("page1 is shown..")
self.start = 10
self.temp = self.start
while self.temp >= 0:
self.timer_label1.config(text = str(self.temp)+ "s")
self.timer_label1.update()
if self.temp == 0:
self.timer_thread._is_running = False
show_frame_g(StartPage)
break
self.temp -=1
sleep(1)
class Page2(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self, parent)
label = ttk.Label(self,text = "Page 2", font = LARGEFONT)
label.grid(row = 0,column = 4,padx=10,pady = 10)
self.img1 = PIL.ImageTk.PhotoImage(file=r'C:\\Users\\mojave\\tkinter\\bg_image2.jpg')
displayCanvas1 = ttk.Label(self)
displayCanvas1.config(image=self.img1)
displayCanvas1.place(x=0,y=0)
button1 = ttk.Button(self, text = "Page 1",command = lambda : controller.show_frame(Page1))
button1.grid(row = 1,column = 1, padx = 10,pady = 10)
button2 = ttk.Button(self,text="Start Page", command = lambda : controller.show_frame(StartPage))
button2.grid(row = 2, column = 1,padx = 10, pady = 10)
self.bind("<<ShowFrame>>", self.on_show_frame)
def on_show_frame(self,event):
print("page2 is shown..")
#self.after(10000,lambda : show_frame_g(StartPage))
app = tkinterApp()
show_frame_g = app.show_frame
#def time_update():
# onTime_page2 =+ 1
def slideShow():
img = next(photos)
displayCanvas.config(image=img)
app.after(1000,slideShow) #after 1s
app.mainloop()
The problem is that the timer of other pages is running in background and randomly takes user to start page. I am not able to figure out how to solve this
I need help inserting text in a Text widget that's part of a Frame.
class Test_frame(Frame):
def __init__(self):
Frame.__init__(self)
self.config(width = 700, height = 450)
self.logs_frame = LabelFrame(self, height = 402, width = 348, text = 'Logs')
self.logs_frame.grid(column = 1, row = 0, pady=10, sticky = N)
self.logs_frame.grid_propagate(0)
self.text_box = Text(self.logs_frame, width=40, pady=10, height=22)
self.text_box.pack(side="left")
self.scroll_y = Scrollbar(self.logs_frame, orient="vertical", command=self.text_box.yview)
self.scroll_y.pack(side="left", expand=True, fill="y")
self.text_box.configure(yscrollcommand=self.scroll_y.set)
self.text_box.insert (?????.END, "Sample Text")
I have no idea how to access that Text widget now.
Test_frame is part of a Notebook:
class App(Tk):
def __init__(self):
Tk.__init__(self)
self.my_notebook = ttk.Notebook(self)
self.my_notebook.pack(pady = 5)
self.frames = {}
for F in (Test_frame, Final_flash_frame):
frame = F()
self.frames[F] = frame
frame.pack(fill = 'both', expand = 1)
self.my_notebook.add(self.frames[Test_frame], text = "Testing")
I created a minimal source, but I guess you solved your problem.
I added a little button to add text, and added some text from outside the class.
Here it is, anyway:
import tkinter as Tk
import tkinter.ttk as ttk
from tkinter import *
def BumpText(textbox):
textbox.insert(END,", MORE TEXT")
class Test_frame(Frame):
def __init__(self):
Frame.__init__(self)
self.config(width = 700, height = 450)
self.logs_frame = LabelFrame(self, height = 402, width = 348, text = 'Logs')
self.logs_frame.grid(column = 1, row = 0, pady=10, sticky = N)
self.logs_frame.grid_propagate(0)
self.text_box = Text(self.logs_frame, width=40, pady=10, height=22)
self.text_box.pack(side="left")
self.scroll_y = Scrollbar(self.logs_frame, orient="vertical", command=self.text_box.yview)
self.scroll_y.pack(side="left", expand=True, fill="y")
self.text_box.configure(yscrollcommand=self.scroll_y.set)
self.text_box.insert(END, "Sample Text")
self.button = Button(self.logs_frame, text="Add\nText", command=lambda:self.text_box.insert(END, ", More Text"))
self.button.pack(side="bottom")
class App(Tk):
def __init__(self):
Tk.__init__(self)
self.my_notebook = ttk.Notebook(self)
self.my_notebook.pack(pady = 5)
self.frames = {}
for F in (Test_frame,): # , Final_flash_frame):
frame = F()
self.frames[F] = frame
frame.pack(fill = 'both', expand = 1)
self.my_notebook.add(self.frames[Test_frame], text = "Testing")
for F,f in self.frames.items():
try:
f.text_box.insert(END," (Added by App)")
except Exception as e:
pass # ignore frames without text_box
if __name__ == "__main__":
App().mainloop()
Ok, so apparently just using:
self.text_box.insert (END, "Sample Text")
works
Cheers,
A
i have a small ui programm and i need to display a calendar in it or a date picker . (NOTE : userid and password is root")**
i have tried this code :
from Tkinter import *
from PIL import Image, ImageTk
import ttkcalendar
class App():
def __init__(self):
pass
root = Tk()
root.configure(bg='black')
root.attributes('-alpha', 0.0)
def mainWindow(self):
self.root.geometry('{}x{}'.format(600,400))
self.root.attributes('-alpha', 1)
self.root.configure(bg='#404040')
self.ttkcal = ttkcalendar.Calendar(self.root,firstweekday=calendar.SUNDAY)
self.ttkcal.pack()
self.root.wm_title("time sheet management system")
# Create the toolbar as a frame
self.toolbar = Frame(self.root, borderwidth=1, relief='raised')
self.toolbar.configure( bg = '#838383')
# Load all the images first as PNGs and use ImageTk to convert
# them to usable Tkinter images.
self.img1 = Image.open('NewIcon.png')
self.useImg1 = ImageTk.PhotoImage(self.img1)
self.img2 = Image.open('LoadIcon.png')
self.useImg2 = ImageTk.PhotoImage(self.img2)
self.img3 = Image.open('SaveIcon.png')
self.useImg3 = ImageTk.PhotoImage(self.img3)
# Set up all the buttons for use on the toolbars.
newBtn = Button(self.toolbar, image=self.useImg1, command=self.callback)
newBtn.pack(side=LEFT, fill=X)
loadBtn = Button(self.toolbar, image=self.useImg2, command=self.callback)
loadBtn.pack(side=LEFT, fill=X)
saveBtn = Button(self.toolbar, image=self.useImg3, command=self.callback)
saveBtn.pack(side=LEFT, fill=X)
# Add the toolbar
self.toolbar.pack(side=TOP, fill=X)
"""
#create a frame
self.infoArea= Frame(self.root, borderwidth=2,height=40,width=100, relief='raised',bg='red')"""
self.root.mainloop()
"""
# Set up a Text box and scroll bar.
self.scrollbar = Scrollbar(self.root)
self.scrollbar.pack(side=RIGHT, fill=Y)
self.text = Text(self.root)
self.text.pack()
self.text.config(yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.text.yview)"""
def loginClick(self):
self.userid = self.txt1.get()
self.password = self.txt2.get()
print self.userid,self.password
if self.password == 'root' and self.userid == 'root':
self.wi.destroy()
self.mainWindow()
def callback(self):
print "A button was pressed"
def login(self):
self.wi = Toplevel (self.root)
#self.wi.geometry('{}x{}'.format(200,200))
self.wi.configure(bg='#404040')
self.wi.overrideredirect(1)
self.wi.update_idletasks()
self.w = self.wi.winfo_screenwidth()
self.h = self.wi.winfo_screenheight()
self.size = tuple(int(_) for _ in self.wi.geometry().split('+')[0].split('x'))
self.x = self.w/2 - self.size[0]/2
self.y = self.h/2 - self.size[1]/2
self.wi.geometry("%dx%d+%d+%d" % (self.size + (self.x, self.y)))
self.wi.geometry('{}x{}'.format(400,200))
self.frame1 = Frame ( self.wi,bg='#404040' )
self.frame1.pack(side=BOTTOM,fill=X)
self.butt1 = Button(self.frame1,text= "Cancel" , bg = '#838383',fg='white',command = self.wi.destroy)
self.butt1.pack(side=RIGHT,padx=1)
self.butt2 = Button(self.frame1,text= "Login" ,bg = '#838383',fg='white',command = self.loginClick)
self.butt2.pack(side=RIGHT)
"""self.frame2 = Frame ( self.wi,bg='green' )
self.frame2.pack(side=BOTTOM,fill=BOTH)"""
self.lab1 = Label (self.wi,text='UserID',bg='#404040',fg='white')
#self.lab1.pack(side=LEFT,padx=60,pady=20)
self.lab1.place(x=60,y=20)
self.lab2 = Label (self.wi,text='Password',bg='#404040',fg='white')
#self.lab1.pack(side=LEFT,padx=60,pady=20)
self.lab2.place(x=60,y=60)
self.txt1 = Entry( self.wi)
self.txt1.place(x=140,y=20)
self.txt2 = Entry( self.wi,show='*')
self.txt2.place(x=140,y=60)
"""
self.label = Label(self.wi,text="UserID",bg='#838383',fg='white')
self.label.place("""
self.wi.mainloop()
if __name__ == "__main__":
a = App()
#a.root.mainloop()
a.login()
but it is giving error that "name calendar not defined". how can i solve this ?
or is there any other way to implement a calendar or date picker in tkinter.
The code is using calendar module, but it is not importing the module.
self.ttkcal = ttkcalendar.Calendar(self.root, firstweekday=calendar.SUNDAY)
^^^^^^^^^^^^^^^
Simply adding following import statement will solve the problem.
import calendar
I'd like to refer to labels in def check(self) . It should check if feedback from external device equals to something, but I don't know how to refer to label and change colour of it if it's equal or not. I'd like to change for example lab3 background to green or red, depending on equality. Here is my code:
# -*- coding: utf-8 -*-
import Tkinter as T, tkFileDialog
import os
from time import *
import serial
from ttk import Button, Label, Frame, Entry, Style
class Program(Frame):
def __init__(self, root):
Frame.__init__(self, root)
self.root = root
self.initUI()
def initUI(self):
self.root.title('OptoMaQ')
Style().configure('TFrame', background = '#6666ff')
Style().configure('TButton',background = '#6666ff')
lab1 = Label(self, text = 'Press Save to save a file', background = '#6666ff').grid(row = 0, columnspan = 5)
but1 = Button(self, text='Save', command=self.save).grid(row = 2,column = 1)
lab2 = Label(self, text = 'Press Exit to quite', background = '#6666ff').grid(row = 1, columnspan = 5)
but2 = Button(self, text = 'Exit',command = self.exit).grid(row = 2, column = 2)
lab3 = Label(self, text = 'Spectra-Hub', background = '#6666ff').grid(row = 3, columnspan = 5)
lab4 = Label(self, text = 'SpectraPro VM-504',background = '#6666ff').grid(row = 4,columnspan = 5)
lab5 = Label(self, text = 'SpectraPro SP-2-300i',background = '#6666ff').grid(row = 5, columnspan = 5)
but3 = Button(self, text = 'Check',command = self.check).grid(row = 6, columnspan = 5)
lab6 = Label(self, text = 'Type sth here', background = '#6666ff').grid(row = 7,columnspan = 5)
self.entry = Entry(self, justify = 'center',text = '1')
self.entry.grid(row = 8, columnspan =3)
self.fileop = options = {}
options['filetypes'] = [('all files', '.*'),('dat files','.dat'),('text files', '.txt')]
options['initialfile'] = 'file.txt'
options['parent'] = root
def check(self):
port = serial.Serial(15)
command = 'WHO'
port.write(command + '\r')
out = port.read(50)
if out == 'Acton Research Corp. \nSpectra-Hub':
lab3 = Label(self, text = 'Spectra-Hub', background = '#6666ff').grid(row = 3, columnspan = 5)
lab3.config(background = 'green')
port.close()
else:
lab3 = Label(self, text = 'Spectra-Hub', background = '#6666ff').grid(row = 3, columnspan = 5)
lab3.config(background = 'red')
port.close()
port2 = serial.Serial(16)
port2.write(command +'\r')
out2 = port2.read(50)
if out2 == 'Acton Research Corp. \nSpectraPro VM-504':
port2.close()
else:
port2.close()
port3 = serial.Serial(17)
port3.write(command + '\r')
out3 = port3.read(46)
if out3 == 'Acton Research Corp. \n SpectraPro SP-2-300i':
port3.close()
else:
port3.close()
def save(self):
filename = tkFileDialog.asksaveasfilename(**self.fileop)
if filename:
file = open(filename, 'a+')
time = strftime("%A, %d %b %Y, %H:%M:%S ", gmtime())
print time
file.write(time)
file.write('\n')
input = str(self.entry.get())
file.write(input)
file.close()
def exit(self):
root.destroy()
if __name__=='__main__':
root = T.Tk()
Program(root).pack()
root.mainloop()
I've tried something like this in lines 46-53 but it doesn't work. It shows that 'NoneType' object has no attribute 'config' in line 52. Any ideas? It's really important to me please help :)
That is because your labels are only defined in the scope of def initUI(self): and therefore inaccessible to def check(self)
Try defining your buttons as self.lab1 instead of lab1 and also refer to them in the same way.