Instead of appending the job_list entry to the list, it replaces the item before when you try to input a new value. I think you can mainly focus on the store_job method, the job number entry and the enter job button. I'm not sure if I need a reset method or something so that the Entry widgets can take more data. Any help would be much appreciated.
from tkinter import *
class EntryGUI:
def __init__(self, parent):
self.cb = IntVar()
self.job_number_label= Label(parent, text = "Job number:")
self.job_number_label.grid(row = 1, column = 0)
self.job_number = Entry(parent)
self.job_number.focus()
self.job_number.grid(row=1, column = 1)
self.customer_name_label = Label(parent, text = "Customer name:")
self.customer_name_label.grid(row = 2, column = 0)
self.customer_name = Entry(parent)
self.customer_name.grid(row=2, column = 1)
self.distance_label= Label(parent, text = "Distance Travelled (km):")
self.distance_label.grid(row = 3, column = 0)
self.distance = Entry(parent)
self.distance.grid(row=3, column = 1)
self.min_spent_label= Label(parent, text = "Minutes spent on Virus protection:")
self.min_spent_label.grid(row = 4, column = 0)
self.min_spent = Entry(parent)
self.min_spent.grid(row=4, column = 1)
wof_tune= Checkbutton(parent, variable = self.cb, text = "check if WOF and tune is required",
onvalue = 100, offvalue = 0)
wof_tune.grid(row = 5, column = 0)
self.enter = Button(parent, text = "Enter Job", command = lambda:[self.store_job(),self.calculate()])
self.enter.grid(row = 6, column = 0)
self.show_all = Button(parent, text = "Show All")
self.show_all.grid(row = 6, column = 1)
def store_job(self):
self.job_list = []
self.customer_list = []
self.job_list.append(self.job_number.get())
self.customer_list.append(self.customer_name.get())
for i in self.job_list:
print (i)
def calculate(self):
self.cost_list = []
self.distance_calc = int(self.distance.get())
self.min_calc = int(self.min_spent.get())
self.cost = 0
#calculates the travel cost
#if the distance is less than 5km it costs 10
if self.distance_calc <= 5:
self.cost = 10
else:
self.distance_calc = self.distance_calc - 5 #-5 as you calclate the extra distance
self.distance_calc = self.distance_calc / 2 #divide by two as you add 50c per km
self.cost = self.distance_calc + 10 #initial 10 plus half the extra distance
#print(self.cost)
self.cost = self.cost + (self.min_calc * 0.8)
self.cost = self.cost + int(self.cb.get())
self.cost_list.append(self.cost)
print(self.cost_list)
self.enter_next()
def enter_next(self):
self.job_number.delete(0,END)
self.customer_name.delete(0, END)
self.distance.delete(0, END)
self.min_spent.delete(0, END)
self.enter.configure(state = NORMAL)
if __name__=="__main__":
root = Tk()
show_label = EntryGUI(root)
root.mainloop()
You were resetting the lists used to store the data entered every time the data is entered; you need to declare storage attributes in __init__, then use them to accumulate the data:
class EntryGUI:
def __init__(self, parent):
self.cb = IntVar()
self.job_number_label = Label(parent, text="Job number:")
self.job_number_label.grid(row=1, column=0)
self.job_number = Entry(parent)
self.job_number.focus()
self.job_number.grid(row=1, column=1)
self.customer_name_label = Label(parent, text="Customer name:")
self.customer_name_label.grid(row=2, column=0)
self.customer_name = Entry(parent)
self.customer_name.grid(row=2, column=1)
self.distance_label = Label(parent, text="Distance Travelled (km):")
self.distance_label.grid(row=3, column=0)
self.distance = Entry(parent)
self.distance.grid(row=3, column=1)
self.min_spent_label = Label(parent, text="Minutes spent on Virus protection:")
self.min_spent_label.grid(row=4, column=0)
self.min_spent = Entry(parent)
self.min_spent.grid(row=4, column=1)
wof_tune= Checkbutton(parent, variable=self.cb, text="check if WOF and tune is required",
onvalue =100, offvalue=0)
wof_tune.grid(row=5, column=0)
self.enter = Button(parent, text="Enter Job", command=self.acquire_entries)
self.enter.grid(row=6, column=0)
self.show_all = Button(parent, text="Show All")
self.show_all.grid(row=6, column=1)
self.job_list = []
self.customer_list = []
self.cost_list = []
def acquire_entries(self):
self.store_job()
self.calculate()
def store_job(self):
self.job_list.append(self.job_number.get())
self.customer_list.append(self.customer_name.get())
def calculate(self):
self.distance_calc = int(self.distance.get())
self.min_calc = int(self.min_spent.get())
self.cost = 0
# ... unchanged below
i am making app that will interact whit MySQL databases, to one table to bee precise. I create main frame, and 3 more, one to show table, one to insert data, and one to delete row using id key. When i start index.py all 3 scripts run, and then main window. I want to user call scripts from menu.
Here is the script:
import wx
from main import SetupGrid
from insert import InsertData
from delete import DeleteData
class GlavniProzor(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Editor Tabele Setup", size = (800,600))
self.createMenu()
self.CenterOnScreen()
self.Show()
def createMenu(self):
''' Traka menija '''
menubar = wx.MenuBar()
self.SetMenuBar(menubar)
''' Meni Specijalne funkcije '''
menu = wx.Menu()
menubar.Append(menu, '&Specijalne funkcije')
menuitem = wx.MenuItem(menu, wx.ID_ANY, 'Tabela')
#self.Bind(wx.EVT_MENU, self.prikazTabele, menuitem)
menu.AppendItem(menuitem)
menuitem = wx.MenuItem(menu, wx.ID_ANY, 'Unos u tabelu')
# self.Bind(wx.EVT_MENU, self.unosuTabelu, menuitem)
menu.AppendItem(menuitem)
menuitem = wx.MenuItem(menu, wx.ID_ANY, 'Brisanje iz tabele')
# self.Bind(wx.EVT_MENU, self.brisanjeizTabele, menuitem)
menu.AppendItem(menuitem)
menuitem = wx.MenuItem(menu, wx.ID_ANY, 'Izlaz')
# self.Bind(wx.EVT_MENU, self.izlaz, menuitem)
menu.AppendItem(menuitem)
def prikazTabele(self, evt):
dial = SetupGrid(self, -1)
dial.CenterOnParent()
dial.Show()
def unosuTabelu(self, evt):
dial = InsertData(self, -1)
dial.CenterOnParent()
dial.Show()
def brisanjeizTabele(self, evt):
dial = DeleteData(self, -1)
dial.CenterOnParent()
dial.Show()
def izlaz(self, evt):
exit()
app = wx.App(0)
frame = GlavniProzor(None)
app.MainLoop()
This is main.py scrip, which show table
#! /usr/bin/env python
import wx, MySQLdb, wx.lib.intctrl
import wx.grid as gridlib
ID_SETUP = 1
db = MySQLdb.connect("127.0.0.1", "user", "password", "database")
class SetupGrid(wx.Dialog):
def __init__(self, id, title='Tabela Setup'):
wx.Dialog.__init__(self, id, title, size=(1000, 300))
db = MySQLdb.connect("127.0.0.1", "root", "aaa111bbb", "mysqlsetup")
cursor = db.cursor()
def setupid():
sql = 'SELECT idSetup FROM setup'
cursor.execute(sql)
rezltat = cursor.fetchall()
rezultat2 = []
x = 0
for upis in rezltat:
for polje in upis:
users = str(polje)
rezultat2.append(users)
x += 1
return rezultat2
def setupkomitent():
sql = 'SELECT idKomitent FROM setup'
cursor.execute(sql)
rezltat = cursor.fetchall()
rezultat2 = []
x = 0
for upis in rezltat:
for polje in upis:
users = str(polje)
rezultat2.append(users)
x += 1
return rezultat2
def setupdrzava():
sql = 'SELECT Drzava FROM setup'
cursor.execute(sql)
rezltat = cursor.fetchall()
rezultat2 = []
x = 0
for upis in rezltat:
for polje in upis:
users = str(polje)
rezultat2.append(users)
x += 1
return rezultat2
def setupprg():
sql = 'SELECT Prg FROM setup'
cursor.execute(sql)
rezltat = cursor.fetchall()
rezultat2 = []
x = 0
for upis in rezltat:
for polje in upis:
users = str(polje)
rezultat2.append(users)
x += 1
return rezultat2
def setupprovajder():
sql = 'SELECT Provajder FROM setup'
cursor.execute(sql)
rezltat = cursor.fetchall()
rezultat2 = []
x = 0
for upis in rezltat:
for polje in upis:
users = str(polje)
rezultat2.append(users)
x += 1
return rezultat2
def setupservername():
sql = 'SELECT ServerName FROM setup'
cursor.execute(sql)
rezltat = cursor.fetchall()
rezultat2 = []
x = 0
for upis in rezltat:
for polje in upis:
users = str(polje)
rezultat2.append(users)
x += 1
return rezultat2
def setupdatabasename():
sql = 'SELECT DataBaseName FROM setup'
cursor.execute(sql)
rezltat = cursor.fetchall()
rezultat2 = []
x = 0
for upis in rezltat:
for polje in upis:
users = str(polje)
rezultat2.append(users)
x += 1
return rezultat2
def setupsifarnici():
sql = 'SELECT Sifarnici FROM setup'
cursor.execute(sql)
rezltat = cursor.fetchall()
rezultat2 = []
x = 0
for upis in rezltat:
for polje in upis:
users = str(polje)
rezultat2.append(users)
x += 1
return rezultat2
def setuppromena():
sql = 'SELECT Promena FROM setup'
cursor.execute(sql)
rezltat = cursor.fetchall()
rezultat2 = []
x = 0
for upis in rezltat:
for polje in upis:
users = str(polje)
rezultat2.append(users)
x += 1
return rezultat2
self.idSetup = setupid()
self.idKomitent = setupkomitent()
self.Drzava = setupdrzava()
self.Prg = setupprg()
self.Provajder = setupprovajder()
self.ServerName = setupservername()
self.DataBaseName = setupdatabasename()
self.Sifarnici = setupsifarnici()
self.Promena = setuppromena()
# Define main panel
panel = wx.Panel(self, -1)
vbox = wx.BoxSizer(wx.VERTICAL)
# Define sizers
# Horizontal sizers
SetupTableSizer = wx.BoxSizer(wx.HORIZONTAL)
BtnSizer = wx.BoxSizer(wx.HORIZONTAL)
# Add species table widget
Setup = wx.grid.Grid(panel, -1, size=(1070, 200))
Setup.CreateGrid(9, 9)
Setup.SetColLabelValue(0, "idSetup")
Setup.SetColLabelValue(1, "idKomitent")
Setup.SetColLabelValue(2, "Drzava")
Setup.SetColLabelValue(3, "Prg")
Setup.SetColLabelValue(4, "Provajder")
Setup.SetColLabelValue(5, "ServerName")
Setup.SetColLabelValue(6, "DataBaseName")
Setup.SetColLabelValue(7, "Sifarnici")
Setup.SetColLabelValue(8, "Promena")
Setup.SetRowLabelSize(0)
for i in range(0, len(self.idSetup)):
Setup.SetCellValue(i, 0, self.idSetup[i])
for i in range(0, len(self.idKomitent)):
Setup.SetCellValue(i, 1, self.idKomitent[i])
for i in range(0, len(self.Drzava)):
Setup.SetCellValue(i, 2, self.Drzava[i])
for i in range(0, len(self.Prg)):
Setup.SetCellValue(i, 3, self.Prg[i])
for i in range(0, len(self.Provajder)):
Setup.SetCellValue(i, 4, self.Provajder[i])
for i in range(0, len(self.ServerName)):
Setup.SetCellValue(i, 5, self.ServerName[i])
for i in range(0, len(self.DataBaseName)):
Setup.SetCellValue(i, 6, self.DataBaseName[i])
for i in range(0, len(self.Sifarnici)):
Setup.SetCellValue(i, 7, self.Sifarnici[i])
for i in range(0, len(self.Promena)):
Setup.SetCellValue(i, 8, self.Promena[i])
Setup.AutoSize()
SetupTableSizer.Add(Setup, wx.ALIGN_CENTER | wx.ALL, 0)
panel.SetSizer(vbox)
self.Centre()
self.Show(True)
app = wx.App()
SetupGrid(None, -1)
app.MainLoop()
This is insert script
import wx
import MySQLdb
db = MySQLdb.connect("127.0.0.1", "user", "password", "database")
cursor = db.cursor()
class InsertData(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
panel = wx.Panel(self, -1)
panel.SetBackgroundColour('light gray')
#iconFile = "Grocery.ico"
#icon1 = wx.Icon(iconFile, wx.BITMAP_TYPE_ICO)
#self.SetIcon(icon1)
label1 = wx.StaticText(panel, -1, "idKomitent:")
label2 = wx.StaticText(panel, -1, "Drzava:")
label3 = wx.StaticText(panel, -1, "Prg:")
label4 = wx.StaticText(panel, -1, "Provajder:")
label5 = wx.StaticText(panel, -1, "ServerName:")
label6 = wx.StaticText(panel, -1, "DataBaseName:")
label7 = wx.StaticText(panel, -1, "Sifarnici:")
self.idKomitent = wx.TextCtrl(panel, -1, "")
self.Drzava = wx.TextCtrl(panel, -1, "")
self.Prg = wx.TextCtrl(panel, -1, "")
self.Provajder = wx.TextCtrl(panel, -1, "")
self.ServerName = wx.TextCtrl(panel, -1, "")
self.DataBaseName = wx.TextCtrl(panel, -1, "")
self.Sifarnici = wx.TextCtrl(panel, -1, "")
self.calc_btn = wx.Button(panel, -1, 'Insert')
self.calc_btn.Bind(wx.EVT_BUTTON, self.onEnter)
self.close = wx.Button(panel, -1, "Exit")
self.Bind(wx.EVT_BUTTON, self.OnCloseMe)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
# use gridbagsizer for layout of widgets
sizer = wx.GridBagSizer(vgap=6, hgap=6)
sizer.Add(label1, pos=(0, 0))
sizer.Add(self.idKomitent, pos=(0, 2)) # row 0, column 2
sizer.Add(label2, pos=(1, 0))
sizer.Add(self.Drzava, pos=(1, 2))
sizer.Add(label3, pos=(2, 0))
sizer.Add(self.Prg, pos=(2, 2))
sizer.Add(label4, pos=(3, 0))
sizer.Add(self.Provajder, pos=(3, 2))
sizer.Add(label5, pos=(4, 0))
sizer.Add(self.ServerName, pos=(4, 2))
sizer.Add(label6, pos=(5, 0))
sizer.Add(self.DataBaseName, pos=(5, 2))
sizer.Add(label7, pos=(6, 0))
sizer.Add(self.Sifarnici, pos=(6, 2))
sizer.Add(self.calc_btn, pos=(8, 1))
sizer.Add(self.close, pos=(8, 2))
# use boxsizer to add border around sizer
border = wx.BoxSizer()
border.Add(sizer, 0, wx.ALL, 20)
panel.SetSizerAndFit(border)
self.Fit()
def onEnter(self, event):
# get the values from the input widgets
idKomitent = int(self.idKomitent.GetValue())
Drzava = str(self.Drzava.GetValue())
Prg = str(self.Prg.GetValue())
Provajder = str(self.Provajder.GetValue())
ServerName = str(self.ServerName.GetValue())
DataBaseName = str(self.DataBaseName.GetValue())
Sifarnici = str(self.Sifarnici.GetValue())
db = MySQLdb.connect("127.0.0.1", "user", "password", "database")
cursor = db.cursor()
cursor.execute("INSERT INTO setup (idKomitent, Drzava, Prg, Provajder, ServerName, DataBaseName, Sifarnici) VALUES (%s, %s, %s, %s, %s, %s, %s)", (idKomitent, Drzava, Prg, Provajder, ServerName, DataBaseName, Sifarnici))
cursor.execute("commit")
self.idKomitent.Clear()
self.Drzava.Clear()
self.Prg.Clear()
self.Provajder.Clear()
self.ServerName.Clear()
self.DataBaseName.Clear()
self.Sifarnici.Clear()
cursor.close()
def OnCloseMe(self, event):
self.Close(True)
def OnCloseWindow(self, event):
self.Destroy()
app = wx.App()
frame = InsertData(None, -1, "Tabela MySQL Setup")
frame.Show()
app.MainLoop()
And final delete script
import wx
import MySQLdb
db = MySQLdb.connect("127.0.0.1", "root", "aaa111bbb", "mysqlsetup")
cursor = db.cursor()
class DeleteData(wx.Frame):
def __init__(self):
wx.Frame.__init__(self)
panel = wx.Panel(self, -1)
panel.SetBackgroundColour('light gray')
#iconFile = "Grocery.ico"
#icon1 = wx.Icon(iconFile, wx.BITMAP_TYPE_ICO)
#self.SetIcon(icon1)
label1 = wx.StaticText(panel, -1, "idSetup:")
self.idSetup = wx.TextCtrl(panel, -1, "")
self.calc_btn = wx.Button(panel, -1, 'Delte')
self.calc_btn.Bind(wx.EVT_BUTTON, self.onEnter)
self.close = wx.Button(panel, -1, "Exit")
self.Bind(wx.EVT_BUTTON, self.OnCloseMe)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
# use gridbagsizer for layout of widgets
sizer = wx.GridBagSizer(vgap=3, hgap=3)
sizer.Add(label1, pos=(0, 0))
sizer.Add(self.idSetup, pos=(0, 2)) # row 0, column 2
sizer.Add(self.calc_btn, pos=(2, 1))
sizer.Add(self.close, pos=(2, 2))
# use boxsizer to add border around sizer
border = wx.BoxSizer()
border.Add(sizer, 0, wx.ALL, 20)
panel.SetSizerAndFit(border)
self.Fit()
def onEnter(self, event):
# get the values from the input widgets
idSetup = int(self.idSetup.GetValue())
db = MySQLdb.connect("127.0.0.1", "user", "password", "database")
cursor = db.cursor()
cursor.execute("DELETE FROM setup WHERE idSetup = '%s'" % (idSetup))
cursor.execute("commit")
self.idSetup.Clear()
cursor.close()
def OnCloseMe(self, event):
self.Close(True)
def OnCloseWindow(self, event):
self.Destroy()
app = wx.App()
frame = DeleteData(None, -1, "Tabela MySQL Setup")
frame.Show()
app.MainLoop()
Where i made mistake??
I think that it might be as simple as adding:
if __name__ == "__main__":
before your app=wx.App() sections
i.e.
if __name__ == "__main__":
app = wx.App(0)
frame = GlavniProzor(None)
app.MainLoop()
Note: using the names ,index,main,insert and delete for your program names is probably a bad idea, they are in danger of being interpreted as keywords if not by python itself by anyone reading the code.
import tkinter as tk ## most of this is for the Bottoni class
from tkinter import *
import os
import string
import PIL.Image
import PIL.ImageTk
import tkinter.ttk
elenco1 = [elemento1, elemento2, elemento3, elemento4]
elenco2 = [elemento5, elemento6, elemento7, elemento8]
elenco3 = [elemento9, elemento10, elemento11, elemento12]
elenco4 = [elemento13, elemento14, elemento15, elemento16]
BOT = [] ## this is for the Bottoni class
IM = [] ## and this too
elenco = elenco1
class ChangeElenco:
def __init__ (self):
def changeElenco(regione):
if regione == "N":
self.elenco = elenco1
elif regione == "K":
self.elenco = elenco2
elif regione == "J":
self.elenco = elenco3
elif regione == "H":
self.elenco = elenco4
elenco = self.elenco
self.radio1 = Radiobutton(text = '1', value = 1, command = lambda : changeElenco("N")).place (x = 920, y = 150)
self.radio2 = Radiobutton(text = '2', value = 2, command = lambda : changeElenco("K")).place (x = 920, y = 170)
self.radio3 = Radiobutton(text = '3', value = 3, command = lambda : changeElenco("J")).place (x = 920, y = 190)
self.radio4 = Radiobutton(text = '4', value = 4, command = lambda : changeElenco("H")).place (x = 920, y = 210)
class secondWindow:
def __init__(self):
self.secondWindow = Tk()
self.secondWindow.geometry ('500x650+400+30')
class Bottoni:
def __init__ (stringa, elenco):
...
def Destroy (self):
...
class mainWindow:
def __init__(self):
self.mainWindow = Tk()
self.mainWindow.geometry ('1130x650+100+10')
self.mainWindow.title('mainWindow')
def mainEnter (self):
testoEntry = StringVar()
testoEntry.set('')
self.mainEntry = Entry(self.mainWindow, textvariable = testoEntry).place (x = 920, y = 20)
def search ():
testoEntry2 = testoEntry.get()
if testoEntry2 == "":
pass
else:
testoEntry2 = testoEntry2.lower()
Bottoni.Destroy(self)
BOT = []
ChangeElenco() ################ here i need the program to change my list "elenco" when i press a radio button
Bottoni(testoEntry2, elenco)
def tracing(a, b, c):
if len(testoEntry.get()) > 2:
search()
testoEntry.trace('w', tracing)
self.button4Entry = Button (self.mainWindow, text = 'search', command = search).place (x = 1050, y = 17)
MW = mainWindow()
ChangeElenco()
MW.mainEnter()
mainloop()
The problem is that in this code, I need the ChangeElenco class to change me the list, and the list I need is the one I choose with the radio button, but in fact it changes just inside the changeElenco function inside that class, and then the list remains the one I had at the beginning...
This question already has answers here:
Tkinter: AttributeError: NoneType object has no attribute <attribute name>
(4 answers)
Closed 7 years ago.
Hello I am making a GUI for a program with Tkinter, but I keep getting an error:
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in __call__
return self.func(*args)
File "C:\Users\jorge\Desktop\new 1.py", line 53, in browse_button
self.browse_entry.delete(0,END)
AttributeError: 'NoneType' object has no attribute 'delete'"
I am a noobie what it comes to classes so I don't know what I'm making wrong.
If you could help me I would appreciate it.
Thanks in advance!!
from Tkinter import *
from tkFileDialog import *
import ttk,os
class App(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
self.title("Subtitles Master")
self.iconbitmap(default = r"C:\Users\jorge\Desktop\Programas Python\notepad.ico")
mainframe = Frame(self)
mainframe.pack(side = "top")
mainframe.grid_rowconfigure(0, weight = 1)
mainframe.grid_columnconfigure(0, weight = 1)
self.frames = {}
for F in (StartPage, Timing):
frame = F(mainframe, 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()
class StartPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
filler1 = Frame(self, width = 30, height = 20).grid(column = 4, row = 0, rowspan = 2)
syncsubs_button = ttk.Button(self, text = "Sync Subtitles", state = DISABLED).grid(column = 5, row = 0)
timing_button = ttk.Button(self, text = "Edit Timing", command = lambda: controller.show_frame(Timing)).grid(column = 5, row = 1)
filler2 = Frame(self, width = 20, height = 20).grid(column = 6, row = 0, rowspan = 2)
syncsubs_label= Label(self, font = ("Alien Encounters", 20), text = "Sync Subtitles", fg = "dark green").grid(row = 2, columnspan = 6)
browse_label = Label(self, font = ("Calibri",12), text = "Subtitles to sync:").grid(row = 3, column = 0, sticky = "w")
filename1 = StringVar()
self.browse_entry = Entry(self, textvariable = filename1, width = 50).grid(row = 4, column = 1, columnspan = 5)
browse_button = ttk.Button(self, text = "Browse", command = self.browse_button).grid(row = 4, column = 0)
def browse_button(self):
filename = askopenfilename(title = "Choose a file",filetypes = (("Subtitles", "*.srt"), ("Text", "*.txt")))
self.browse_entry.delete(0,END)
self.browse_entry.insert(0,filename)
return filename
class Timing(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
filler1 = Frame(self, width = 30, height = 20).grid(column = 4, row = 0, rowspan = 2)
syncsubs_button = ttk.Button(self, text = "Sync Subtitles", command = lambda: controller.show_frame(StartPage)).grid(column = 5, row = 0)
timing_button = ttk.Button(self, text = "Edit Timing", state = DISABLED).grid(column = 5, row = 1)
filler2 = Frame(self, width = 20, height = 20).grid(column = 6, row = 0, rowspan = 2)
syncsubs_label= Label(self, font = ("Alien Encounters", 20), text = "Edit Timing", fg = "dark red").grid(row = 2, columnspan = 6)
window = App()
window.mainloop()
The problem is this line:
# returns None (Entry.grid(...))
self.browse_entry = Entry(self, textvariable = filename1, width = 50).grid(row = 4, column = 1, columnspan = 5)
Change to two lines:
# returns entry
self.browse_entry = Entry(self, textvariable = filename1, width = 50)
# do stuff with entry
self.browse_entry.grid(row = 4, column = 1, columnspan = 5)
Working on a Python 2.7.10 program, for a password gui but it is giving the error that Application is not defined. I am not sure if there is something wrong with Class Application(Frame) or app = Application(root), because it ask for me to define Application but I don't why they would ask me.
from Tkinter import *
class Application(Frame):
def _init_(self, master):
Frame._init_(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.instruction = Label(self, text = "Enter the password")
self.instruction.grid(row = 0, column = 0, columnspan = 2, sticky = W)
self.password = Entry(self)
self.password.grid(row = 1, column = 1, sticky = W)
self.submit_button = Button(self, text = "Submit", commmand = self.reveal)
self.submit_button.grid(row = 2, column = 0, sticky = W)
self.text = Text(self, width = 35, height = 5, wrap = WORD)
self.text.grid(row = 3, column = 0, columnspan = 2, sticky = W)
def reveal(self):
content = self.password.get()
if content == "password":
message = "You have the order"
else:
message = "Access denied."
self.text.delete(0.0, END)
self.text.insert(0.0, message)
root = Tk()
root.title("Password")
root.geometry("250x150")
app= Application(root)
root.mainloop()
I've fixed your code, here it is:
from Tkinter import *
class Application(Frame):
def __init__(self, master):
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.instruction = Label(self, text = "Enter the password")
self.instruction.grid(row = 0, column = 0, columnspan = 2, sticky = W)
self.password = Entry(self)
self.password.grid(row = 1, column = 1, sticky = W)
self.submit_button = Button(self, text = "Submit", command = self.reveal)
self.submit_button.grid(row = 2, column = 0, sticky = W)
self.text = Text(self, width = 35, height = 5, wrap = WORD)
self.text.grid(row = 3, column = 0, columnspan = 2, sticky = W)
def reveal(self):
content = self.password.get()
if content == "password":
message = "You have the order"
else:
message = "Access denied."
self.text.delete(0.0, END)
self.text.insert(0.0, message)
root = Tk()
root.title("Password")
root.geometry("250x150")
app= Application(root)
root.mainloop()
Your problems were:
You used _init_ instead of __init__
Typo of "commmand" instead of "command"
Last two lines of procedure reveal in Application were incorrectly indented (logic error, not syntax or run-time)
It wasn't really clear what your question was to be honest and I just did this in Python 3.4.3 and made changes so that it should run in Python 2.7.10. I hope that helps.