4 Replies - 499 Views - Last Post: 23 August 2012 - 08:01 PM Rate Topic: -----

#1 andrewborg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 23-August 12

Opening a Window From a Window

Posted 23 August 2012 - 12:04 AM

Hi,

I am having problems opening a Window from another Python window.

I am creating an Application with Python where the user is displayed a Main Menu where he can choose further options.

The problem I am facing is how to create a new Window when the user clicks on an option

Thank you,
Andrew Borg
Is This A Good Question/Topic? 0
  • +

Replies To: Opening a Window From a Window

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Opening a Window From a Window

Posted 23 August 2012 - 06:37 AM

We don't know your error and we haven't seen your code, all we know is you have a "problem". With this little information, how can anyone possibly help you?
Was This Post Helpful? 0
  • +
  • -

#3 duffman18  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 54
  • Joined: 20-October 10

Re: Opening a Window From a Window

Posted 23 August 2012 - 10:04 AM

Yes, more information is definately needed. If you could show code, tell us what OS you are trying to run this on, and what GUI toolkit you are using. It would also be helpful to know what you have already tried. With this info I'm sure someone on here can steer you in the right direction.
Was This Post Helpful? 0
  • +
  • -

#4 andrewborg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 23-August 12

Re: Opening a Window From a Window

Posted 23 August 2012 - 01:02 PM

Hi Guys,

Below is the python code for the application I am creating.

Note that this is not fully Functional and there may be some discrepancies.


#!/usr/bin/python

from gi.repository import Gtk
import sqlite3

class AddCustomer(Gtk.Window):

	def __init__(self):
		Gtk.window.__init__(self, title="Add Customer")
		
		Table = Gtk.Table(5, 5, True)
		
		# Labels
		
		ShopLabel 		= 		Gtk.Label 	(label = "Shop Name")
		
		NameLabel 		= 		Gtk.Label	(label = "Customer Name")
		
		SurnameLabel 		= 		Gtk.Label	(label = "Customer Surname")
		
		NumberLabel		=		Gtk.Label	(label = "Contact Number")
		
		EmailLabel 		= 		Gtk.Label	(label = "Email Address")
		
		VatLabel 		= 		Gtk.Label 	(label = "Vat Number")
		
		#TextBoxes
		
		self.ShopNameText	=		Gtk.Entry()

		self.NameText		=		Gtk.Entry()
		
		self.SurnameText	=		Gtk.Entry()
		
		self.NumberText		=		Gtk.Entry()
		
		self.EmailText		=		Gtk.Entry()
		
		self.VatText		=		Gtk.Entry()
		
		#Buttons
		
		ResetButton 		= 		Gtk.Button(label = "Reset")
		ResetButton.connect	("clicked", self.ResetButton_Clicked)
		
		SubmitButton 		= 		Gtk.Button(label = "Submit")
		SubmitButton.connect	("clicked", self.SubmitButton_Clicked)
		
		#Table Placement
		
		Table.attach(ShopLabel, 0, 1, 0, 1, ypadding = 10)
		Table.attach(self.ShopNameText, 1, 2, 0, 1, ypadding = 10)
		
		Table.attach(NameLabel, 0, 1, 1, 2, ypadding = 10)
		Table.attach(self.NameText, 1, 2, 1, 2, ypadding = 10)
		
		Table.attach(SurnameLabel, 2, 3, 1, 2, ypadding = 10)
		Table.attach(self.SurnameText, 3, 4, 1, 2, ypadding = 10)
		
		Table.attach(NumberLabel, 0, 1, 2, 3, ypadding = 10)
		Table.attach(self.NumberText, 1, 2, 2, 3, ypadding = 10)
		
		Table.attach(EmailLabel, 2, 3, 2, 3, ypadding = 10)
		Table.attach(self.EmailText, 3, 4, 2, 3, ypadding = 10)
		
		Table.attach(VatLabel, 0, 1, 3, 4, ypadding = 10)
		Table.attach(self.VatText, 1, 2, 3, 4, ypadding = 10)
		
		Table.attach(ResetButton, 0, 1, 4, 5, ypadding = 10)
		Table.attach(SubmitButton, 2, 3, 4, 5, ypadding = 10)
		
		self.add(Table)
		
	def ResetButton_Clicked(self, widget):
		self.ShopNameText.set_text("")
		self.NameText.set_text("")
		self.SurnameText.set_text("")
		self.NumberText.set_text("")
		self.EmailText.set_text("")
		self.VatText.set_text("")
		
	def SubmitButton_Clicked(self, widget):
		Connection = sqlite3.connect('Test.DB')
		C = Connection.cursor()
		
		C.execute('''CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)''')
             
             	Connection.commit()
             	C.close()
		
Window = AddCustomer()
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()


On this Form there is a button To Add a Customer, Although what it realy does is create a Table called Stocks, but I am just doing this to learn Python.

What I want is for Example when the Submit Button is Clicked, the Python application displays the Main Menu, which is located in another .py file

I am using Linux with the GTK Toolkit.

Thank You for your Help,

Andrew Borg

This post has been edited by Simown: 23 August 2012 - 05:23 PM
Reason for edit:: Code tags

Was This Post Helpful? 0
  • +
  • -

#5 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Opening a Window From a Window

Posted 23 August 2012 - 08:01 PM

I need to spend some time looking at this code, I won't be able to tonight. However, you should look at PEP 8: Style Guide for Python, particularly, whitespace in expression statements.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1