Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter Gui Menu Addition Error
Hey guys, I am having an issue with my Python 3.71 Tkinter GUI class that I have been writing. I am relatively new to Python and the present code is an amalgam of online tutorials found at the top ten links found on google through "Python Tkinter GUI tutorial" google search.

I have a link to the Stackoverflow post for the code and history of the question, but I would very much appreciate any of your help, feedback, and critique.

from tkinter import *
from tkinter import ttk
import tkinter.scrolledtext as tkst
import os
import tkinter as tk
from functools import partial
from PIL import Image, ImageTk

class UserGui(tk.Tk):

	def __init__(self,parent):

	def widgets(self):
		self.frame1_style = ttk.Style()
		self.frame1_style.configure('My.TFrame', background='white')
		self.frame2_style = ttk.Style()

		self.frame1 = ttk.Frame(self.parent, style='My.TFrame') #Creating Total Window Frame 1
		self.frame1.grid(row=0, column=0, sticky=(N, S, E, W))

		self.frame2 = ttk.Frame(self.parent, width=100, height=20, style='My2.TFrame')
		self.frame2.grid(row=0, column=6, padx=20, pady=5)

		self.newText = tkst.ScrolledText(master=self.frame2, wrap=tk.WORD, width=50, height=10)
		self.newText.grid(row=0, column=6)

		self.firstNameLabel = ttk.Label(self.frame1, text="First Name")
		self.firstName = ttk.Entry(self.frame1)
		self.lastNameLabel = ttk.Label(self.frame1, text="Last Name")
		self.lastName = ttk.Entry(self.frame1)

		self.optList1 = [
		self.optList2 = [
		self.var1 = StringVar(self.parent)
		self.var1.set(self.optList1[0]) #first value default

		self.var2 = StringVar(self.parent)
		self.var1.set(self.optList2[0]) #first value default

		self.optMenu1 = ttk.OptionMenu(self.frame1, self.var1, self.optList1[0], *self.optList1)
		self.optMenu2 = ttk.OptionMenu(self.frame1, self.var2, self.optList2[0], *self.optList2)

		self.rConfigNameLabel = ttk.Label(self.frame1, text="Sel1: ")
		self.rModeNameLabel = ttk.Label(self.frame1, text="Sel2: ")

		self.saveButton_style = ttk.Style()
		self.saveButton_style.configure('newButton.TButton', background='#404040')
		self.saveButton = ttk.Button(self.frame1, text="Save and Quit", command=self.parent.quit, style='newButton.TButton')
		self.showButton = ttk.Button(self.frame1, text="Show Entries", command=partial(self.showEntryFields), style='newButton.TButton')
		#Grid Call Collection
		self.firstNameLabel.grid(row=0, column=0, sticky=W, padx=5)
		self.firstName.grid(row=0, column=1, sticky=(N, E, W), padx=5, pady=5)
		self.lastNameLabel.grid(row=1, column=0, sticky=W, padx=5)
		self.lastName.grid(row=1, column=1, sticky=(N, E, W), padx=5, pady=5)
		self.optMenu1.grid(row=2, column=1, padx=5,pady=5)
		self.optMenu2.grid(row=3, column=1, pady=5)
		self.rConfigNameLabel.grid(row=2, column=0, sticky=W, padx=5)
		self.rModeNameLabel.grid(row=3, column=0, sticky=W, padx=5)
		self.saveButton.grid(row=4, column=1, sticky=W, padx=5, pady=20)
		self.showButton.grid(row=4, column=0, sticky=W, padx=5, pady=20)
		#Menu Creation
		self.menu1 = tk.Menu(self.parent, tearoff=0)
		self.fileMenu = tk.Menu(self.menu1, tearoff=0)
		self.fileMenu.add_command(label="Open", command=self.donothing)
		self.fileMenu.add_command(label="Save", command=self.donothing)


		self.fileMenu.add_command(label="Exit", command=self.parent.quit)
		self.fileMenu.add_cascade(label="File", menu=self.menu1)

		self.editMenu = tk.Menu(self.menu1, tearoff=0)
		self.editMenu.add_command(label="Cut", command=self.donothing)
		self.editMenu.add_command(label="Copy", command=self.donothing)
		self.editMenu.add_command(label="Paste", command=self.donothing)
		self.editMenu.add_cascade(label="Edit", menu=self.menu1)	

	def showEntryFields(self):
		if __name__ == "__main__":
			print("First Name: %s\nLast Name: %s" % (self.firstName.get(), self.lastName.get()))
			print("Sel1: %s\nSel2: %s" % (self.var1.get(),self.var2.get()))

	def donothing(self):
		filewin = Toplevel(self.parent)
		button = Button(filewin, text="Do nothing button")


def main():

if __name__ == '__main__':
Thank you for your time. Smile
what is the 'Menu Addition Error'? You mention but don't identify the issue.
Apologies, it is not an actual error reported by tcl or Python in a terminal. It was an error that was hidden throughout dependency issues. My code
was adding
, which is the opposite ordering of what I wanted to accomplish with the

After I switched the ordering to
I was properly attributing the editMenu to menu1 and it showed without error. This fix was listed as one of the comments in the StackOverflow post.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Tkinter error for a scheduled event Ceegen 5 193 Jan-14-2019, 09:24 PM
Last Post: Ceegen
  Dropdown menu- Store variable aking76 1 301 Sep-11-2018, 01:30 PM
Last Post: aking76
  Menu bar not showing in gui window mlh 2 355 Sep-09-2018, 10:27 PM
Last Post: mlh
  [Tkinter] [python]Problem in creating menu[/python] yamoon 10 565 Aug-01-2018, 09:01 PM
Last Post: Larz60+
  [Tkinter] Tkinter optionmenu child menu position showing 0,0 thatguy14 2 476 Jun-15-2018, 10:42 AM
Last Post: thatguy14
  [Tkinter] [SOLVED] Create per button popup menu py2.7 AceScottie 5 758 May-31-2018, 12:39 AM
Last Post: AceScottie
  printing option menu variable in label in Tkinter SmokerX 1 1,430 Jan-18-2018, 07:36 PM
Last Post: SmokerX
  [Tkinter] No menu bar in window bde69 5 2,023 Nov-25-2017, 06:35 PM
Last Post: heiner55
  Tkinter's strange error Ponomarenko Pavlo 7 1,637 Jul-20-2017, 06:12 PM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)