I'm working in pyGTK (completely new to it) and I need to display a tic-tac-toe board. It doesn't have to keep track of the game state, just place Xs and Os on click. Unfortunately, I can't get all 9 buttons to show. Currently, I'm trying to use 3 HButtonBoxes of 3 buttons each packed into an VBox. Unfortunately, I get a blank window when I run.
I'm running Python 2.5.1 on Ubuntu Gutsy. -
import pygtk
-
import gtk
-
-
class TicTacToe:
-
def main(self):
-
gtk.main()
-
-
def destroy(self, widget, data=None):
-
gtk.main_quit()
-
-
def setC(self, widget, event, data=None):
-
widget.set_label(self.current)
-
if self.current == 'X':
-
self.current = 'Y'
-
else:
-
self.current = 'X'
-
print "Clicked!"
-
-
def delete_event(self, widget, event, data = None):
-
print "Delete event occurred"
-
return False
-
-
def __init__(self):
-
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
-
self.buttonbox1 = gtk.HButtonBox()
-
self.button1=gtk.Button()
-
self.button2=gtk.Button()
-
self.button3=gtk.Button()
-
self.button1.connect('clicked', self.setC, None)
-
self.button2.connect('clicked', self.setC, None)
-
self.button3.connect('clicked', self.setC, None)
-
self.buttonbox1.pack_start(self.button1)
-
self.buttonbox1.pack_start(self.button2)
-
self.buttonbox1.pack_start(self.button3)
-
self.current = 'X'
-
-
self.window.connect("destroy", window.destroy)
-
self.window.connect_object("delete_event", self.delete_event)
-
-
self.buttonbox2 = gtk.HButtonBox()
-
self.button4=gtk.Button()
-
self.button5=gtk.Button()
-
self.button6=gtk.Button()
-
self.button4.connect('clicked', self.setC, None)
-
self.button5.connect('clicked', self.setC, None)
-
self.button6.connect('clicked', self.setC, None)
-
self.buttonbox2.pack_start(self.button4)
-
self.buttonbox2.pack_start(self.button5)
-
self.buttonbox2.pack_start(self.button6)
-
-
self.buttonbox3 = gtk.HButtonBox()
-
self.button7=gtk.Button()
-
self.button8=gtk.Button()
-
self.button9=gtk.Button()
-
self.buttonbox3.pack_start(self.button7)
-
self.buttonbox3.pack_start(self.button8)
-
self.buttonbox3.pack_start(self.button9)
-
self.button7.connect('clicked', self.setC, None)
-
self.button8.connect('clicked', self.setC, None)
-
self.button9.connect('clicked', self.setC, None)
-
-
self.this = gtk.VBox(False, 2)
-
self.this.pack_start(self.buttonbox1)
-
self.this.pack_start(self.buttonbox2)
-
self.this.pack_start(self.buttonbox3)
-
-
self.button1.show()
-
self.button2.show()
-
self.button3.show()
-
self.button4.show()
-
self.button5.show()
-
self.button6.show()
-
self.button7.show()
-
self.button8.show()
-
self.button9.show()
-
self.buttonbox1.show()
-
self.buttonbox2.show()
-
self.buttonbox3.show()
-
self.this.show()
-
self.window.show()
-
-
if __name__ == "__main__":
-
tic = TicTacToe()
-
tic.main()
2 1787
i rewrote your entire program to try and figure out what you done wrong, cuz i culd not see what it whas.
And then when i got to the end of my own program i noticed what whas missing! You forgot to add your VBox 'this' to the window!
self.window.add(self.this)
:)
Here is my version anyway: -
#!/usr/bin/env python
-
# coding: UTF-8
-
-
import pygtk
-
pygtk.require('2.0')
-
import gtk
-
-
class TicTacToe:
-
-
-
def destroy(self, widget, data=None):
-
gtk.main_quit()
-
-
def delete_event(self, widget, event, data=None):
-
print "delete event!"
-
return False
-
-
def create(self):
-
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
-
self.window.connect("destroy", self.destroy)
-
self.window.connect("delete_event", self.delete_event)
-
-
self.table = gtk.Table(rows=3, columns=3, homogeneous=True)
-
self.buttons = [gtk.Button(label="button %d" % i) for i in xrange(9)]
-
for button in self.buttons:
-
button.connect('clicked', self.setOwner)
-
-
def layout(self):
-
for widget in zip(self.buttons, [(i,b) for i in range(3) \
-
for b in range(3)]):
-
self.table.attach(widget[0], widget[1][0], widget[1][0]+1,\
-
widget[1][1], widget[1][1]+1)
-
self.window.add(self.table)
-
-
def show(self):
-
for button in self.buttons:
-
button.show()
-
self.table.show()
-
self.window.show()
-
-
def setOwner(self, widget, data=None):
-
pass
-
-
def main(self):
-
gtk.main()
-
-
def __init__(self):
-
self.create()
-
self.layout()
-
self.show()
-
-
if __name__ == "__main__":
-
board = TicTacToe()
-
board.main()
-
*facepalm* Thank you...*feels like a moron*
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Edwin Young |
last post by:
Hi,
I'm writing a fractal-generating program in a mixture of C and
Python. Python handles all the GUI parts using PyGTK. After finishing
the calculations, I have a buffer containing the RGB data...
|
by: j_mckitrick |
last post by:
Hi all. Here is a tiny container for one of each combo box, along
with the glade file. Just 2 widgets, so hopefully not too large. How
the heck do I get the selection from the ComboBox, as...
|
by: Mark Mitchell |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I have a program written in python that tells me it requires PyGTK, so I
DLed, ./configure, make, make install and the process seems to go ok. Some...
|
by: Egbert Bouwman |
last post by:
As a newby to PyGTK I already have produced some gui's I like,
but I have difficulties in finding out what method or other instrument
I need for doing various things.
I have not yet found the...
|
by: Thomas Bartkus |
last post by:
I am experimenting (flailing around?) with glade and python. Both under MS
Windows and Linux.
I understand why I want to "import gtk"
It gives me access to the critical gui program loop...
|
by: TPJ |
last post by:
GUI's etc: PyGtk on Windows
"(...) So if someone develops mainly for X and just wants to make sure
that it is not impossible to run on Windows, you can use PyGTK. (...)",
July 2nd, 1999
pyGTK...
|
by: Rod W |
last post by:
I'm just starting out on Python but my primary goal is to provide
applications with some user interface (GUI).
Can someone point me to a good comparison of whether I should use
wxPython (with...
|
by: krishnakant Mane |
last post by:
hello,
I will be writing some code in PyGTK to run on linux. but I want to
know if there are any installers or distutils available for PyGTK on
windows?
I have heard that installing gimp or even...
|
by: He Jibo |
last post by:
Hi, Everyone,
Could someone help me how to install pygtk? I get some problems with
it.
Here is the error I get while install pygtk:
https://netfiles.uiuc.edu/jibohe2/error.GIF?uniq=-k6678k
...
|
by: Michael Palmer |
last post by:
On Sep 16, 12:30 pm, binaryjesus <coolman.gu...@gmail.comwrote:
I haven't tried it myself, but I came across a blog post the other day
that describes a way of building windows installers for...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |