I'm writing a program that draws a rectangle or oval in a top frame depending on whether or not the user selects it via a radiobutton. There is a check button that determines whether the oval is filled as well. Both buttons are on the bottom frame. But for some reason when I run the code, it displays the window, but not the buttons themselves. How do I fix this?
Here's my code:
from tkinter import *
class GeometricFigures:
def __init__(self):
self.window = Tk()
self.window.title("Radiobuttons and Checkbuttons")
self.canvas = Canvas(self.window, width = 300, height = 100, bg = "white")
self.canvas.pack()
def drawButtons(self):
self.bottomframe = Frame(self.window)
self.bottomframe.pack()
self.check = IntVar()
cbtFilled = Checkbutton(self.bottomframe, variable = self.check, value = 0,
text = "Filled", command = self.processCheckbutton).pack(side = LEFT)
self.radio = IntVar()
rbRectangle = Radiobutton(self.bottomframe, variable = self.radio, value = 1,
text = "Rectangle", command = self.processRadiobutton.pack())
rbOval = Radiobutton(self.bottomframe, text = "Oval", variable = self.radio,
value = 2, command = self.processRadiobutton.pack())
cbtFilled.grid(row = 1, column = 2)
rbRectangle.grid(row = 1, column = 3)
rbOval.grid(row = 1, column = 4)
def processCheckbutton(self):
print("The check button is " +
("checked " if self.check.get() == 1 else "unchecked"))
def processRadiobutton(self):
print(("Rectangle" if self.radio.get() == 1 else "Oval")
+ " is selected ")
def drawRect(self):
self.canvas.create_rectangle(30, 10, 270, 60, tags = "rect")
def drawFillOval(self):
self.canvas.create_oval(30, 10, 270, 60, fill = 'blue', tags = "oval")
def drawOval(self):
self.canvas.create_oval(30, 10, 270, 60, tags = "oval")
def main(self):
test = GeometricFigures()
if self.check.get() == 1:
test.drawFillOval()
if self.radio.get() == 1:
test.drawRect()
else:
test.drawOval()
test.drawButtons()
if __name__ == '__main__':
main()
Thanks!
Related
I am constructing a messaging application, and using Tkinter for GUI. I am trying to create some buttons, but I receive an error message:
Traceback (most recent call last):
File "/home/artur/Documents/MScProject/MSc Project/Task #179276/main_program.py", line 174, in <module>
app = Application(the_window)
File "/home/artur/Documents/MScProject/MSc Project/Task #179276/main_program.py", line 49, in __init__
self.AES_radiobutton = Radiobutton(text = 'AES algorithm', bg = color, variable=self.var, value=0)
NameError: name 'Radiobutton' is not defined
I am posting all of the source code here:
import tkinter as tk
from tkinter import IntVar
from tkinter import messagebox
from tkinter import Frame
from tkinter import Frame
from tkinter import Text
from tkinter import Label
from AESEncDec import *
from MD5Hashing import *
from RSAEncDec import *
color = 'lightblue' #color our background
class Application(Frame):
def __init__(self, root=None):
Frame.__init__(self, root)
self.frame_width = 700
self.frame_height = 400
# Set configuration our frame
self.config(width = self.frame_width, height = self.frame_height, bg = color)
self.pack()
# Create textBox for input data
self.textbox_one = Text()
self.textbox_one.place(x = 30, y = 170, height = 200, width = 300 )
# Create textBox for result
self.textbox_two = Text()
self.textbox_two.place(x = 370, y = 170, height = 200, width = 300 )
label_input_text = Label( text = "Input text: ", bg = color)
label_input_text.place(x = 30, y = 155, height = 10, width = 70 )
label_output_text = Label( text = "Result: ", bg = color)
label_output_text.place(x = 370, y = 155, height = 10, width = 50 )
# IntVar help to detect, what radioButton was chosen
self.var = IntVar()
# Create radioButton for AES
self.AES_radiobutton = Radiobutton(text = 'AES algorithm', bg = color, variable=self.var, value=0)
self.AES_radiobutton.place(x = 100, y = 20, height = 30, width = 100 )
# Create radioButton for DSA
self.DSA_radiobutton = Radiobutton(text = 'DSA algorithm', bg = color, variable=self.var, value=1)
self.DSA_radiobutton.place(x = 100, y = 70, height = 30, width = 100 )
# Create radioButton for Hash function
self.HF_radiobutton = Radiobutton(text = 'Hash function', bg = color, variable=self.var, value=2)
self.HF_radiobutton.place(x = 100, y = 120, height = 30, width = 100 )
# Create label
self.lable_for_ask_bits = Label(text = 'Input size of bits:', bg = color)
self.lable_for_ask_bits.place(x = 210, y = 70, height = 30, width = 100 )
# Create textBox for input bits
self.input_bits = Text()
self.input_bits.place(x = 310, y = 75, height = 20, width = 50 )
self.input_bits.insert(INSERT, '16')
# Create button to encrypt text
self.encrypt_button = Button(root, text = "Encrypt text", command = self.encrypt_text)
self.encrypt_button.place(x = 420, y = 20, height = 80, width = 100 )
# Create button to decrypt text
self.decrypt_button = Button(root, text = "Decrypt text", command = self.decrypt_text)
self.decrypt_button.place(x = 540, y = 20, height = 80, width = 100 )
# Create button to hash
self.hash_button = Button(root, text = "Hash text", command = self.hashing )
self.hash_button.place(x = 420, y = 120, height = 30, width = 220)
# Create AES object, keyword "this is a very strong key"
# You can change keyword
self.AES = AESEncDec('this is a very strong key')
# Save bits
self.bit_length = 16
# Create RSA object
self.RSA = RSAEncDec(self.bit_length)
def encrypt_text(self):
self.textbox_two.delete("1.0", END)
# Get radioButton selection
selection = self.var.get()
# if chosen AES
if selection == 0:
# Read text from input
message = self.textbox_one.get("1.0", END)
encrypt_message = self.AES.encrypt(message)
# Output result
self.textbox_two.insert(INSERT, encrypt_message)
# if chosen RSA
elif selection == 1:
try:
# Read number of bits
tmp_bits = int(self.input_bits.get("1.0", END))
# if bits not in range from 4 to 32 print error message
if tmp_bits < 4 or tmp_bits > 32:
tkMessageBox.showerror(message ='Bits must be in range from 4 to 32')
else:
# else, if tmp_bits not = self.bit_length: create new object
if tmp_bits != self.bit_length:
self.bit_length = tmp_bits
self.RSA = RSAEncDec(self.bit_length)
except:
tkMessageBox.showerror(message ='You must input integer number')
# Find max number
max_number = self.RSA.get_max_value_to_encrypt()
try:
# Read text from input (myst be number)
message = int(self.textbox_one.get("1.0", END))
if message < 0 or message > max_number:
tkMessageBox.showerror(message ='Input text must be number in range from 0 to ' + str(max_number))
else:
encrypt_message = self.RSA.encrypt(message)
# Output result
self.textbox_two.insert(INSERT, encrypt_message)
except:
tkMessageBox.showerror(message ='Input text must be number in range from 0 to ' + str(max_number))
else:
tkMessageBox.showinfo(message ='You must select "AES" or "RSA" radioButton')
def decrypt_text(self):
self.textbox_two.delete("1.0", END)
# Get radioButton selection
selection = self.var.get()
# if chosen AES
if selection == 0:
# Read text from input
message = self.textbox_one.get("1.0", END)
decrypt_message = self.AES.decrypt(message)
# Output result
self.textbox_two.insert(INSERT, decrypt_message)
elif selection == 1:
# Read text from input
message = int(self.textbox_one.get("1.0", END))
decrypt_message = self.RSA.decrypt(message)
# Output result
self.textbox_two.insert(INSERT, decrypt_message)
else:
tkMessageBox.showinfo(message ='You must select "AES" or "RSA" radioButton')
def hashing(self):
# Get radioButton selection
selection = self.var.get()
# if chosen Hash function
if selection == 2:
# Read text from input
message = self.textbox_one.get("1.0", END)
# Hashing
hashing_message = Hashing(message)
# Output result
self.textbox_two.insert(INSERT, hashing_message)
else:
tkMessageBox.showinfo(message ='You must select "Hash function" radioButton')
#create object TK class
the_window = tk.Tk(className = " Cryptographic")
#create object Application
app = Application(the_window)
#run our Application
app.mainloop()
I still see the GUI though and an input box, but a lot of elements are missing. What might be the problem here?
Simple import of Radiobutton module solved the issue
Major programming noob here, and my very first question in stackoverflow. I'm trying to make a time reaction tester, with a simplistic Tkinter GUI.
Here's the code
#!/usr/bin/env python
import tkinter as tk
import time
import random
class TRTest(tk.Frame):
def __init__(self, master = None):
super().__init__()
self.grid()
self.canv()
self.createWidgets()
self.Test
self.totalt = []
def createWidgets(self):
self.quitbtn = tk.Button(self, text = "Quit", command=self.master.destroy)
self.quitbtn.grid(row = 3, column = 3)
self.label = tk.Label(self, text = "TRTest")
self.label.grid(row = 1, column = 3)
self.testbtn = tk.Button(self, text = "Start test", command = self.Test)
self.testbtn.grid(row = 1, column = 2)
def canv(self):
self.scrn = tk.Canvas(self, width = 400, height = 400, bg = "#E8E8E8")
self.scrn.grid(row = 2, column = 3)
def fixate(self):
self.scrn.create_line(190, 200, 210, 200, width = 2)
self.scrn.create_line(200, 190, 200, 210, width = 2)
def createCircle(self):
self.scrn.create_oval(150, 150, 250, 250, fill = "red", tag = "circle")
def Test(self):
if len(self.totalt) == 0:
self.fixate()
self.update()
self.bind_all("<Key>", self.gettime)
self.after(random.randint(1000, 5000))
self.t0 = time.clock()
self.createCircle()
def gettime(self, event):
t = time.clock() - self.t0
self.totalt.append(t)
self.scrn.delete("circle")
if len(self.totalt) < 6:
self.Test
else:
print(self.totalt)
a = tk.Tk()
b = TRTest(a)
b.mainloop()
It should be making 5 trials and returning the list of the measured TR times, but it freezes before showing a second circle. Where's the problem?
In addition to the answer from Patrick Haugh, you aren't using the .after method correctly.
Change this line of code
self.after(random.randint(1000, 5000))
to
self.after(random.randint(1000, 5000),self.Test)
and move it to after
if len(selftotalt) < 6:
This will call the self.Test function again after a random period of time between 1 and 5 seconds.
If more 6 or more reaction times have been captures it will no longer call the function again but print out the times.
Full code that seem to work for me
import tkinter as tk
import time
import random
class TRTest(tk.Frame):
def __init__(self, master = None):
super().__init__()
self.grid()
self.canv()
self.createWidgets()
self.totalt = []
def createWidgets(self):
self.quitbtn = tk.Button(self, text = "Quit", command=self.master.destroy)
self.quitbtn.grid(row = 3, column = 3)
self.label = tk.Label(self, text = "TRTest")
self.label.grid(row = 1, column = 3)
self.testbtn = tk.Button(self, text = "Start test", command = self.Test)
self.testbtn.grid(row = 1, column = 2)
def canv(self):
self.scrn = tk.Canvas(self, width = 400, height = 400, bg = "#E8E8E8")
self.scrn.grid(row = 2, column = 3)
def fixate(self):
self.scrn.create_line(190, 200, 210, 200, width = 2)
self.scrn.create_line(200, 190, 200, 210, width = 2)
def createCircle(self):
self.scrn.create_oval(150, 150, 250, 250, fill = "red", tag = "circle")
def Test(self):
if len(self.totalt) == 0:
self.fixate()
self.update()
self.bind_all("<Key>", self.gettime)
self.t0 = time.clock()
self.createCircle()
def gettime(self, event):
t = time.clock() - self.t0
self.totalt.append(t)
self.scrn.delete("circle")
if len(self.totalt) < 6:
self.after(random.randint(1000, 5000),self.Test)
else:
print(self.totalt)
a = tk.Tk()
b = TRTest(a)
b.mainloop()
I think you are trying to run the method Test with
self.Test
Try instead
self.Test()
I'm writing a scientific calculator with 2nd button. What is the function for second button so for example it changes sin to sin^-1, plus changing the sin button command; and if you click the 2nd button again, it changes sin^-1 back to sin
I would split my calculator up into section using different frames (one to show the calculations , one with buttons which won't have 2 functions and lastly the buttons which have 2 functions).
The reason I would split it up is because I would use destroying objects and making the new ones this splitting up means you can destroy the wanted frame rather than specific buttons (would require less code). Also for this I would have 3 create GUI defs. one would be the buttons with one function and the bit showing the calculations. one be the buttons which have 2 functions (their first function) and lastly the buttons which have 2 functions (their second functions). To decide between which GUI gen def to use have an if statement with global variable which gets changed each time 2nd function button called and that decides which def to use.
If it was just commands you wanted changing instead of both labels and commands I would have a variable which is etheir 1 or 2(change when 2nd button clicked) then in your definitions (ones which your buttons call) have an if statement to decide between to do normal action (e.g cos) or 2nd action (e.g cos-1).
Here is code below that uses what i have described in the first paragraph:
from tkinter import *
class Calc(Frame):
def __init__(self, master):
self.modefunction = 1
""" Initialize the frame. """
super(Calc,self).__init__(master)
self.grid()
self.calculations_frm = Frame(self, width=100, height=30)#bg = "red"
self.calculations_frm.grid(row = 0, column = 0, columnspan=2)
self.buttons_frm = Frame(self, width= 50, height=30,)#bg = "green")
self.buttons_frm.grid(row = 1, column = 1)
self.buttons_2_functions_1_frm = Frame(self, width=50, height=30)#bg = "blue")
self.buttons_2_functions_1_frm.grid(row = 1, column = 0)
self.create_GUI()
def create_show_calculations(self):
self.calculation_lbl = Label(self.calculations_frm, text = "will show caluclations here").pack()
def create_buttons(self):
#mc stands for mode change
self.mode_change_btn = Button(self.buttons_frm, text = "mc", command = self.mode_change, height = 1, width = 5)
self.mode_change_btn.grid(row = 0,column = 0)
self.plus_btn = Button(self.buttons_frm, text = "plus", height = 1, width = 5)
self.plus_btn.grid(row = 1,column = 0)
def create_GUI(self):
self.create_show_calculations()
self.create_buttons()
self.create_1_function_gui()
def create_1_function_gui(self):
self.tan_btn = Button(self.buttons_2_functions_1_frm, text = "tan", height = 1, width = 5)
self.tan_btn.grid(row = 0,column = 0)
self.san_btn = Button(self.buttons_2_functions_1_frm, text = "san", height = 1, width = 5)
self.san_btn.grid(row = 0,column = 1)
self.coz_btn = Button(self.buttons_2_functions_1_frm, text = "coz", height = 1, width = 5)
self.coz_btn.grid(row = 1,column = 0)
def create_2_function_gui(self):
self.buttons_2_functions_2_frm = Frame(self, width=50, height=30)#bg = "blue")
self.buttons_2_functions_2_frm.grid(row = 1, column = 0)
self.inverse_tan_btn = Button(self.buttons_2_functions_2_frm, text = "tan-1", height = 1, width = 5)
self.inverse_tan_btn.grid(row = 0,column = 0)
self.inverse_san_btn = Button(self.buttons_2_functions_2_frm, text = "san-1", height = 1, width = 5)
self.inverse_san_btn.grid(row = 0,column = 1)
self.inverse_coz_btn = Button(self.buttons_2_functions_2_frm, text = "coz-1", height = 1, width = 5)
self.inverse_coz_btn.grid(row = 1,column = 0)
def mode_change(self):
if self.modefunction == 1:
self.buttons_2_functions_1_frm.destroy()
self.modefunction = 2
self.buttons_2_functions_2_frm = Frame(self, width=50, height=30)#bg = "blue")
self.buttons_2_functions_2_frm.grid(row = 1, column = 0)
self.create_2_function_gui()
else:
self.buttons_2_functions_2_frm.destroy()
self.modefunction = 1
self.buttons_2_functions_1_frm = Frame(self, width=50, height=30)#bg = "blue")
self.buttons_2_functions_1_frm.grid(row = 1, column = 0)
self.create_1_function_gui()
root = Tk()
root.title("booking system")
root.geometry("500x500")
root.configure(bg="white")
app = Calc(root)
root.mainloop()
from tkinter import *
import tkinter.messagebox
from ProjectHeader import *
class Gui(object):
def __init__(self, parent):
self.gui = parent
self.gui.geometry("350x200")
self.gui.title("Converter")
self.checked1 = IntVar()
self.checked2 = IntVar()
self.c1 = Radiobutton(self.gui, text='(1)Centimeters', variable=self.checked1, value = 1)
self.c2 = Radiobutton(self.gui, text='(2)Meter', variable=self.checked1, value = 2)
self.c3 = Radiobutton(self.gui, text='(3)Millimeters', variable=self.checked1, value = 3)
self.c4 = Radiobutton(self.gui, text='(4)Kilometers', variable=self.checked1, value = 4)
self.c5 = Radiobutton(self.gui, text='(5)Centimeters', variable=self.checked2, value = 5)
self.c6 = Radiobutton(self.gui, text='(6)Meter', variable=self.checked2, value = 6)
self.c7 = Radiobutton(self.gui, text='(7)Millimeters', variable=self.checked2, value = 7)
self.c8 = Radiobutton(self.gui, text='(8)Kilometers', variable=self.checked2, value = 8)
self.b1 = Button(self.gui, text="Convert", command=self.callback)
self.l1 = Label(self.gui, text="Value")
self.l2 = Label(self.gui, text="Convert ->")
self.e1 = Entry(self.gui, bd = 5)
self.e1.insert(0, "0")
self.c1.pack(side = BOTTOM)
self.c2.pack(side = BOTTOM)
self.c3.pack(side = BOTTOM)
self.c4.pack(side = BOTTOM)
self.c5.pack(side = BOTTOM)
self.c6.pack(side = BOTTOM)
self.c7.pack(side = BOTTOM)
self.c8.pack(side = BOTTOM)
self.l1.pack(side = TOP)
self.l2.pack(side = TOP)
self.e1.pack(side = TOP)
self.b1.pack(side = TOP)
self.c1.place(x = 3, y = 90)
self.c2.place(x = 3, y = 110)
self.c3.place(x = 3, y = 130)
self.c4.place(x = 3, y = 150)
self.c5.place(x = 235, y = 90)
self.c6.place(x = 235, y = 110)
self.c7.place(x = 235, y = 130)
self.c8.place(x = 235, y = 150)
self.l2.place(x = 140, y = 110)
def callback(self):
if self.e1.get() == "0":
messagebox.showinfo("Error", "Please enter a value")
elif self.checked1.get(): #Centiemters
C = Centimeters(self.e1.get())
if self.checked2.get():
messagebox.showinfo("Error", "Converting the same unit!")
if self.checked2.get():
value = C.ToMeters()
messagebox.showinfo("Value", str(value) + ' cm')
if self.checked2.get():
value = C.ToMillimeters()
messagebox.showinfo("Value", str(value) + ' cm')
if self.checked2.get():
value = C.ToKilometers()
messagebox.showinfo("Value", str(value) + ' cm')
root = Tk()
my_window = Gui(root)
root.mainloop()
so now I changed the self.checked1.get() == 1 to self.checked1.get()
because you said by checking on the radiobutton, it would select the option
but now, when I the check the (1)Centimeters button, or either (5)Centimeters to (8)Kilometers button, the program would select all the options
for example, if I checked (1)Centimeters button and (8)Kilometers, the program would pop up not only converted value of Kilometers, but also the converted value of meters, millimeters.
so my question is how can I fix the program that when I checked the 1st box on the left side, and either one of the boxes on the right side, the program would give the correct selection?
Here is the interface of checkedbutton
http://postimg.org/image/6uqwkybw5/
If I understand what you want correctly, you should use the following code. Use self.checked1.get() to see what is the original unit and use self.checked2.get() to see to which unit it has to be converted.
if self.e1.get() == "0":
messagebox.showinfo("Error", "Please enter a value")
elif self.checked1.get() == 1: #Centimeters
C = Centimeters(self.e1.get())
if self.checked2.get() == 5:
messagebox.showinfo("Error", "Converting the same unit!")
if self.checked2.get() == 6:
value = C.ToMeters()
messagebox.showinfo("Value", str(value) + ' m')
if self.checked2.get() == 7:
value = C.ToMillimeters()
messagebox.showinfo("Value", str(value) + ' mm')
if self.checked2.get() == 8:
value = C.ToKilometers()
messagebox.showinfo("Value", str(value) + ' km')
what i have is a window that opens up and it has a list box. this is created using one class. when i click the search button and results are found using a different class, i want the list box to update without having to open up another window. below is my code so far\n
from Tkinter import *
class addTask:
def __init__(self):
self.addWindow = Tk()
self.addWindow.configure(background = "black")
self.addWindow.geometry("450x450")
self.addWindow.resizable(width = False, height = False)
self.addWindow.title("Add Task")
self.addNameLabel = Label(self.addWindow,text="Add the name of the task",font = ("Helvetica",10,"italic"),bg = "black",fg = "white")
self.addNameLabel.place(relx=0.01, rely=0.05)
self.nameWiget = Text (self.addWindow, width = 63, height = 1)
self.nameWiget.place(relx=0.0, rely=0.1)
self.addDateLabel = Label(self.addWindow,text="Add the date of the task",font = ("Helvetica",10,"italic"),bg = "black",fg = "white")
self.addDateLabel.place(relx=0.01, rely=0.2)
self.dateWiget = Text (self.addWindow, width = 63, height = 1)
self.dateWiget.place(relx=0.0, rely=0.25)
self.addTaskLabel = Label(self.addWindow,text="Add the details of the task",font = ("Helvetica",10,"italic"),bg = "black",fg = "white")
self.addTaskLabel.place(relx=0.01, rely=0.35)
self.taskWiget = Text (self.addWindow, width = 63, height = 1)
self.taskWiget.place(relx=0.0, rely=0.4)
addButton = Button(self.addWindow,height = 5, width = 20, text="Add Task",highlightbackground="black",font=("Helvetica",10,"bold"),command=lambda:self.saveFuntion())
addButton.place(relx=0.25, rely=0.55)
def saveFuntion(self):
nameInfo = (self.nameWiget.get(1.0, END))
dateInfo = self.dateWiget.get(1.0, END)
taskInfo = self.taskWiget.get(1.0, END)
print nameInfo
task1 = Task(nameInfo,dateInfo,taskInfo)
task1.save()
self.nameWiget.delete(1.0,END)
class Task:
def __init__(self,name,date,task):
self.__name = name
self.__date = date
self.__task = task
def save(self):
fileName = open("dataFile.txt","a")
fileName.write(self.__name)
fileName.write(self.__date)
fileName.write(self.__task)
class editTask:
def __init__(self):
self.editWindow = Tk()
self.newWindow = Tk()
self.newWindow.geometry("450x750")
self.editWindow.configure(background = "black")
self.editWindow.geometry("450x750")
self.editWindow.resizable(width = False, height = False)
self.editWindow.title("Edit Task")
self.listBox = Listbox(self.editWindow,heigh = 15, width = 30)
self.listBox.place(relx = 0.2, rely = 0.6)
#drop down menu
self.var = StringVar(self.editWindow)
self.var.set("Select search critria")
self.choices = ["Name","Date"]
self.option = OptionMenu(self.editWindow,self.var,*self.choices)
self.option.configure(bg = "black")
self.option.place(relx = 0.5, rely = 0.2)
#edit label and text box
self.editLabel = Label(self.editWindow,text="Add the name of the task",font = ("Helvetica",10,"italic"),bg = "black",fg = "white")
self.editLabel.place(relx=0.01, rely=0.05)
self.editInfoWiget = Text (self.editWindow, width = 63, height = 1)
self.editInfoWiget.place(relx=0.0, rely=0.1)
# search button
searchButton = Button(self.editWindow,height = 5, width = 20, text="Search for Task",highlightbackground="black",font=("Helvetica",10,"bold"),command=lambda:self.searchFuntion())
searchButton.place(relx=0.3, rely=0.4)
def searchFuntion(self):
critria = self.var.get()
info = self.editInfoWiget.get(1.0,END)
thing = info.split("\n")
thing2 = thing[0]
search = searchCritria(critria,thing2)
search.search()
# def openListBox(self):
class searchCritria():
def __init__(self,critria,info):
self.__critria = critria
self.__info = info
def search(self):
self.file = open("dataFile.txt", "r+")
fileData = self.file.readlines()
self.file.close()
lengthOfFile = len(fileData)
counter = 1
self.name = []
self.date = []
self.details = []
for i in range (lengthOfFile):
split = fileData[i].split("\n")
while counter == 1:
self.name.append(split)
break
while counter == 2:
self.date.append(split)
break
while counter == 3:
self.details.append(split)
break
counter = counter +1
if counter > 3:
counter = 1
if self.__critria == "Name":
for x in range (len(self.name)):
self.taskName = self.name[x]
self.taskName2 = self.taskName[0]
if self.__info == self.taskName2:
openWindow = True
else :
openWindow = False
if openWindow == True:
editTask().listBox.insert(END,self.taskName2)
if self.__critria == "Date":
for x in range (len(self.date)):
self.taskDate = self.date[x]
self.taskDate2 = self.taskDate[0]
if self.__info == self.taskDate2:
print "found"
else :
print"not found"
class editTask2():
def __init__(self):
self.edit2Window = Tk()
self.edit2Window.configure(background = "black")
self.edit2Window.geometry("450x350")
self.edit2Window.resizable(width = False, height = False)
self.edit2Window.title("Edit Task")
any help would be great
thanks
The biggest problem in your code is that you're creating multiple instances of Tk. Tkinter simply isn't designed to work that way. You should only ever create a single instance of Tk. If you need additional windows, create instances of Toplevel.
Also, you need to call the mainloop function of this instance of Tk exactly once. Without it, your GUI will not work.
If you want to update a listbox in another class than where it was created, the concept is pretty simple: if A needs to update B, A needs a reference to B. So, either pass in a reference to the listbox when you create the other class, or give the other class a method you can call where you pass in the reference to the listbox after it was created.