Is it even possible...I am not sure. Here is my code so far when I click on the Prog_1_Database buttons I want a window to pop up with more button widgets in. Currently the button widget unfortunately gets added to the top level

Here is the code so far:

#! /GWD/appbase/tools/bin/python2.5

import sys,os,re,string
from sys import exit
from random import randint
from Tkinter import *

aaz = 0
aab = 0
class Application(Frame):
	def say_hi(self):
		print """Hello and welcome to the Prog_1 and Prog_2 database builder please select the type of database you wish to build and choose the property restrictions you wish to impose"""		

	def createWidgets(self):
		
		#create quit button
		self.QUIT = Button(self)
		self.QUIT["text"] = "QUIT"
		self.QUIT["fg"]   = "blue"
		self.QUIT["command"] = self.quit
		self.QUIT.pack({"side": "right"})
		
		#create hi button
		self.hi_there = Button(self)
		self.hi_there["text"] = "Hello",
		self.hi_there["command"] = self.say_hi
		self.hi_there.pack({"side": "left"})
		
		#Create Prog_1_Database button
		self.Prog_1 = Button(self)
		self.Prog_1["text"] = "Prog_1_Database",
		self.Prog_1["command"] = self.Begin_Prog_1_Database_Building
		self.Prog_1.pack({"side": "left"})
		
		#Create Prog_2_Database button
		self.Prog_2 = Button(self)
		self.Prog_2["text"] = "Prog_2_Database",
		self.Prog_2["command"] = self.Begin_Prog_2_Database_Building
		self.Prog_2.pack({"side": "left"})
		
	def Addnewbutton(self):
		self.NEWBUTTON = Button()
		self.NEWBUTTON["text"] = "Newbutton",
		self.NEWBUTTON["fg"]   = "Red"
		self.NEWBUTTON["command"] = self.quit # this makes newbutton exit
		self.NEWBUTTON.pack({"side": "left"})
	
	def Begin_Prog_1_Database_Building(self):
		
		print "You are Beginning the Process of Prog_1 Database Building"
		global aaz
		aaz = aaz + 1
		if aaz < 3:
			win = Toplevel()
			message = "Please Select Prog_1 Database Property Criteria"
			Label(win, text=message).pack()
			win.title("Prog_1 Database Property Criteria")
			win.NEWBUTTON = Button()
			win.NEWBUTTON["text"] = "Newbutton",
			win.NEWBUTTON["fg"]   = "Red"
			win.NEWBUTTON["command"] = self.quit # this makes newbutton exit
			#win.NEWBUTTON["flash()"]
			win.NEWBUTTON.pack({"side": "right"})
		else: 
			print "too many windows restart program"

			
		#self.Addnewbutton()
			
	def Begin_Prog_2_Database_Building(self):
		
		print "You are Beginning the Process of Prog_2 Database Building"
		global aab
		aab = aab + 1
		if aab < 3:
			wake = Toplevel()
			message = "Please Select Prog_2 Database Property Criteria"
			Label(wake, text=message).pack()
			wake.title("Prog_2 Database Property Criteria")
			#self.Addnewbutton() #Doesn't work as it should
		else:
			print "too many windows restart program"
			
	def __init__(self, master=None):
	
		Frame.__init__(self, master)
		self.pack()
		self.createWidgets()

All help greatly appreciated

Recommended Answers

All 4 Replies

I think you should pass the root window to Toplevel:

from Tkinter import *
root = Tk()
win2 = Toplevel(root)

Including just that code does not help. That just opens up a new window with nothing in. Thanks anyway for trying.

Including just that code does not help. That just opens up a new window with nothing in. Thanks anyway for trying.

Works for me:

from Tkinter import *


def make_sub():
    def say_hello():
        win2.button['text'] = 'Hello' if win2.button['text'] != 'Hello' else 'Works'
        
    win2 = Toplevel(root)
    win2.button = Button(win2, text='Click me', command=say_hello)
    win2.button.pack()


root = Tk()
root.button = Button(root, text='Make', command=make_sub)
root.button.pack()
root.mainloop()

thankyou that works I can figure out how to mix it into my code now cheers tony

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.