Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44569 > unrolled thread

in need of some help...

Started byAlex Norton <ayjayn1101@gmail.com>
First post2013-04-30 15:06 -0700
Last post2013-05-12 12:34 -0700
Articles 20 on this page of 22 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  in need of some help... Alex Norton <ayjayn1101@gmail.com> - 2013-04-30 15:06 -0700
    Re: in need of some help... Chris Angelico <rosuav@gmail.com> - 2013-05-01 08:13 +1000
      Re: in need of some help... Alex Norton <ayjayn1101@gmail.com> - 2013-04-30 15:30 -0700
        Re: in need of some help... Ian Kelly <ian.g.kelly@gmail.com> - 2013-04-30 17:02 -0600
          Re: in need of some help... Alex Norton <ayjayn1101@gmail.com> - 2013-04-30 16:20 -0700
            Re: in need of some help... Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-01 00:01 -0400
            Re: in need of some help... Chris Angelico <rosuav@gmail.com> - 2013-05-01 14:37 +1000
              Re: in need of some help... Alex Norton <ayjayn1101@gmail.com> - 2013-05-01 03:27 -0700
            Re: in need of some help... jt@toerring.de (Jens Thoms Toerring) - 2013-05-01 12:15 +0000
              Re: in need of some help... Alex Norton <ayjayn1101@gmail.com> - 2013-05-01 16:24 -0700
              Re: in need of some help... Alex Norton <ayjayn1101@gmail.com> - 2013-05-10 01:23 -0700
                Re: in need of some help... jt@toerring.de (Jens Thoms Toerring) - 2013-05-11 22:20 +0000
                  Re: in need of some help... Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-05-12 17:59 +0200
                    Re: in need of some help... jt@toerring.de (Jens Thoms Toerring) - 2013-05-12 21:56 +0000
                      Re: in need of some help... Chris Angelico <rosuav@gmail.com> - 2013-05-13 08:18 +1000
                        Re: in need of some help... jt@toerring.de (Jens Thoms Toerring) - 2013-05-12 22:58 +0000
                          Re: in need of some help... Chris Angelico <rosuav@gmail.com> - 2013-05-13 09:08 +1000
                      Re: in need of some help... Chris Angelico <rosuav@gmail.com> - 2013-05-13 10:51 +1000
                      Re: in need of some help... Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-12 19:47 -0400
                        Re: in need of some help... Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-05-13 20:10 +1200
                  Re: in need of some help... Chris Angelico <rosuav@gmail.com> - 2013-05-13 02:08 +1000
                  Re: in need of some help... Alex Norton <ayjayn1101@gmail.com> - 2013-05-12 12:34 -0700

Page 1 of 2  [1] 2  Next page →


#44569 — in need of some help...

FromAlex Norton <ayjayn1101@gmail.com>
Date2013-04-30 15:06 -0700
Subjectin need of some help...
Message-ID<1bdc367a-4187-440b-85a8-de69360bc71d@googlegroups.com>
hi, 

i am currently trying to make a rock paper scissors game based on a game.

the code for the game itself works fine, it does what i need it to do

the issue i am having is that i haven't a clue how to combine the game code i have with the QT GUI code i have. 

[toc] | [next] | [standalone]


#44570

FromChris Angelico <rosuav@gmail.com>
Date2013-05-01 08:13 +1000
Message-ID<mailman.1201.1367360008.3114.python-list@python.org>
In reply to#44569
On Wed, May 1, 2013 at 8:06 AM, Alex Norton <ayjayn1101@gmail.com> wrote:
>
> hi,
>
> i am currently trying to make a rock paper scissors game based on a game.
>
> the code for the game itself works fine, it does what i need it to do
>
> the issue i am having is that i haven't a clue how to combine the game code i have with the QT GUI code i have.

Poke around with some QT examples, or play with Tkinter (which comes
with Python). Get a "hello, world" going, then expand on it. If you
get stuck, come back to the list with a bit more information and,
preferably, code; at the moment, your request is so vague that all I
can offer is highly general advice.

ChrisA

[toc] | [prev] | [next] | [standalone]


#44571

FromAlex Norton <ayjayn1101@gmail.com>
Date2013-04-30 15:30 -0700
Message-ID<001fe0f1-9124-4cbb-bc84-1b58ee7b8138@googlegroups.com>
In reply to#44570
On Tuesday, April 30, 2013 11:13:24 PM UTC+1, Chris Angelico wrote:
> On Wed, May 1, 2013 at 8:06 AM, Alex Norton <ayjayn1101@gmail.com> wrote:
> 
> >
> 
> > hi,
> 
> >
> 
> > i am currently trying to make a rock paper scissors game based on a game.
> 
> >
> 
> > the code for the game itself works fine, it does what i need it to do
> 
> >
> 
> > the issue i am having is that i haven't a clue how to combine the game code i have with the QT GUI code i have.
> 
> 
> 
> Poke around with some QT examples, or play with Tkinter (which comes
> 
> with Python). Get a "hello, world" going, then expand on it. If you
> 
> get stuck, come back to the list with a bit more information and,
> 
> preferably, code; at the moment, your request is so vague that all I
> 
> can offer is highly general advice.
> 
> 
> 
> ChrisA

thanks... i have made the Tkinter hello world before and thats simple

below is the RPS game coding 


import pygame, sys

from pygame.locals import * 


import random


#############################################################################


#game message
print
print
print
print('Welcome to the Elements game')
print('Water, Earth, Fire, and Air')
print('Type quit to exit the game')
print


#variables for the elements
water = 1

earth = 2

fire = 3

air = 4

#game core mechanic
while 1:

	#Z is the computer, the randint is to allow the randomisation of the integers the computer will choose
	z = random.randint (1, 4)
	
	#A is the you, this is to allow you to enter an integer yourself and not a randomisation.
	a = int (input ('Water, Earth, Fire, Air :----->'))
	
	#the choices you make and the results
	if a ==  z :
		print ('Stalemate')
		
	if a == water and z == earth:
		print ('Water smashes against Earth and Does nothing, Stalemate')
		
	if a == water and z == fire:
		print (' Water hits fire and douses the flames, you win!')
		
	if a == water and z == air:
		print (' Water misses the Air, you lose')
	
	if a == earth and z == water:
		print (' Earth hits Water and does nothing, Stalemate')
		
	if a == earth and z == fire:
		print('Earth is sorched by Fire, you lose')
		
	if a == earth and z == air:
		print('Earth snuffs the Air, you win!')
		
	if a == fire and z == water:
		print('fire is doused by Water, you lose')
	
	if a == fire and z == earth:
		print ('fire sorches Earth, you win!')
	
	if a == fire and z == air:
		print('Fire misses Air, Stalemate')
		
	if a == air  and z == water:
		print('Air removes Water, you win!')
		
	if a == air and z == earth:
		print(' Air is dispatched by Earth, you lose')
		
	if a == air and z == fire:
		print('Air  shakes fire but does nothing, Stalemate')
	
	if a == quit:
		break
	
		
print('Thank you for playing the Elements game')

oh FYI its for my college course.. i didnt really want to use Visual Basic so the teacher cannot help

below is the QT GUI Code

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'GUI.ui'
#
# Created: Tue Apr 30 22:36:27 2013
#      by: PyQt4 UI code generator 4.10.1
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(762, 578)
        MainWindow.setMinimumSize(QtCore.QSize(762, 578))
        MainWindow.setMaximumSize(QtCore.QSize(762, 578))
        MainWindow.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8("../../../../Users/Alex Norton/Desktop/Avatar-The-Last-Airbender.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.widget = QtGui.QWidget(self.centralwidget)
        self.widget.setGeometry(QtCore.QRect(30, 21, 701, 521))
        self.widget.setObjectName(_fromUtf8("widget"))
        self.verticalLayout_4 = QtGui.QVBoxLayout(self.widget)
        self.verticalLayout_4.setMargin(0)
        self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4"))
        self.lblTitle = QtGui.QLabel(self.widget)
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Viner Hand ITC"))
        font.setPointSize(24)
        font.setBold(True)
        font.setWeight(75)
        self.lblTitle.setFont(font)
        self.lblTitle.setObjectName(_fromUtf8("lblTitle"))
        self.verticalLayout_4.addWidget(self.lblTitle)
        self.verticalLayout_3 = QtGui.QVBoxLayout()
        self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
        self.horizontalLayout_2 = QtGui.QHBoxLayout()
        self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
        self.verticalLayout = QtGui.QVBoxLayout()
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
        self.lblWater = QtGui.QLabel(self.widget)
        self.lblWater.setMinimumSize(QtCore.QSize(200, 175))
        self.lblWater.setMaximumSize(QtCore.QSize(200, 175))
        self.lblWater.setText(_fromUtf8(""))
        self.lblWater.setPixmap(QtGui.QPixmap(_fromUtf8(":/imagery/Water.png")))
        self.lblWater.setObjectName(_fromUtf8("lblWater"))
        self.verticalLayout.addWidget(self.lblWater)
        self.lblFire = QtGui.QLabel(self.widget)
        self.lblFire.setMinimumSize(QtCore.QSize(200, 175))
        self.lblFire.setMaximumSize(QtCore.QSize(200, 175))
        self.lblFire.setText(_fromUtf8(""))
        self.lblFire.setPixmap(QtGui.QPixmap(_fromUtf8(":/imagery/Fire.png")))
        self.lblFire.setObjectName(_fromUtf8("lblFire"))
        self.verticalLayout.addWidget(self.lblFire)
        self.horizontalLayout_2.addLayout(self.verticalLayout)
        self.verticalLayout_2 = QtGui.QVBoxLayout()
        self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
        self.lblEarth = QtGui.QLabel(self.widget)
        self.lblEarth.setMinimumSize(QtCore.QSize(200, 175))
        self.lblEarth.setMaximumSize(QtCore.QSize(200, 175))
        self.lblEarth.setText(_fromUtf8(""))
        self.lblEarth.setPixmap(QtGui.QPixmap(_fromUtf8(":/imagery/Earth.png")))
        self.lblEarth.setObjectName(_fromUtf8("lblEarth"))
        self.verticalLayout_2.addWidget(self.lblEarth)
        self.lblAir = QtGui.QLabel(self.widget)
        self.lblAir.setMinimumSize(QtCore.QSize(200, 175))
        self.lblAir.setMaximumSize(QtCore.QSize(200, 175))
        self.lblAir.setText(_fromUtf8(""))
        self.lblAir.setPixmap(QtGui.QPixmap(_fromUtf8(":/imagery/Air.png")))
        self.lblAir.setObjectName(_fromUtf8("lblAir"))
        self.verticalLayout_2.addWidget(self.lblAir)
        self.horizontalLayout_2.addLayout(self.verticalLayout_2)
        self.verticalLayout_3.addLayout(self.horizontalLayout_2)
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
        self.lblOutput = QtGui.QLabel(self.widget)
        self.lblOutput.setText(_fromUtf8(""))
        self.lblOutput.setObjectName(_fromUtf8("lblOutput"))
        self.horizontalLayout.addWidget(self.lblOutput)
        self.btnFinish = QtGui.QPushButton(self.widget)
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Viner Hand ITC"))
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.btnFinish.setFont(font)
        self.btnFinish.setObjectName(_fromUtf8("btnFinish"))
        self.horizontalLayout.addWidget(self.btnFinish)
        self.verticalLayout_3.addLayout(self.horizontalLayout)
        self.verticalLayout_4.addLayout(self.verticalLayout_3)
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QObject.connect(self.btnFinish, QtCore.SIGNAL(_fromUtf8("pressed()")), MainWindow.close)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "Avatar: The Last Airbender", None))
        self.lblTitle.setText(_translate("MainWindow", "Avatar: The Last Airbender Elements Game", None))
        self.btnFinish.setText(_translate("MainWindow", "Finish", None))

import elements_rc



basically i want to have it so that the element images in the GUI are linked with their corresponding variable(water with lblWater) and in the background the computer selects their own random integer and the results are displayed in the lblOutput.

[toc] | [prev] | [next] | [standalone]


#44574

FromIan Kelly <ian.g.kelly@gmail.com>
Date2013-04-30 17:02 -0600
Message-ID<mailman.1202.1367363021.3114.python-list@python.org>
In reply to#44571
On Tue, Apr 30, 2013 at 4:30 PM, Alex Norton <ayjayn1101@gmail.com> wrote:
> oh FYI its for my college course.. i didnt really want to use Visual Basic so the teacher cannot help

If the course is being taught in Visual Basic then that would probably
be the best thing to use.  I'm surprised that the teacher is allowing
you to complete the assignment in Python if he/she doesn't know the
language.

> basically i want to have it so that the element images in the GUI are linked with their corresponding variable(water with lblWater) and in the background the computer selects their own random integer and the results are displayed in the lblOutput.

I'm not all that familiar with PyQt specifically, but I can tell you
that GUI programs are typically event-based rather than simply
procedural like your RPS game.  That means that the "while 1" loop
that you have will be replaced with the Qt event loop.  You will also
need to write event handlers for each of the four element labels, so
that when a user clicks on one of them, the game will go through the
logic of receiving the player's choice (based on which one was
clicked), determining the result of the match, and finally updating
the output label accordingly.

[toc] | [prev] | [next] | [standalone]


#44575

FromAlex Norton <ayjayn1101@gmail.com>
Date2013-04-30 16:20 -0700
Message-ID<47292460-b601-47e7-bdba-ccdc5f0d1c27@googlegroups.com>
In reply to#44574
On Wednesday, 1 May 2013 00:02:51 UTC+1, Ian  wrote:
> On Tue, Apr 30, 2013 at 4:30 PM, Alex Norton <ayjayn1101@gmail.com> wrote:
> 
> > oh FYI its for my college course.. i didnt really want to use Visual Basic so the teacher cannot help
> 
> 
> 
> If the course is being taught in Visual Basic then that would probably
> 
> be the best thing to use.  I'm surprised that the teacher is allowing
> 
> you to complete the assignment in Python if he/she doesn't know the
> 
> language.
> 
> 
> 
> > basically i want to have it so that the element images in the GUI are linked with their corresponding variable(water with lblWater) and in the background the computer selects their own random integer and the results are displayed in the lblOutput.
> 
> 
> 
> I'm not all that familiar with PyQt specifically, but I can tell you
> 
> that GUI programs are typically event-based rather than simply
> 
> procedural like your RPS game.  That means that the "while 1" loop
> 
> that you have will be replaced with the Qt event loop.  You will also
> 
> need to write event handlers for each of the four element labels, so
> 
> that when a user clicks on one of them, the game will go through the
> 
> logic of receiving the player's choice (based on which one was
> 
> clicked), determining the result of the match, and finally updating
> 
> the output label accordingly.

thanks... ill take a look at the Qt event handling

the teacher actually cant teach anything, he as the knowledge of Vb but his teaching methods are abysmal and severely lacking, but he said we can use any language we feel more comfortable in. some are using VB others PHP and some in C ++.
 the reason i chose python was because i could understand it ( simple python) better than any worksheet or notes he made

[toc] | [prev] | [next] | [standalone]


#44577

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-05-01 00:01 -0400
Message-ID<mailman.1204.1367380905.3114.python-list@python.org>
In reply to#44575
On Tue, 30 Apr 2013 16:20:02 -0700 (PDT), Alex Norton
<ayjayn1101@gmail.com> declaimed the following in
gmane.comp.python.general:


> the teacher actually cant teach anything, he as the knowledge of Vb but his teaching methods are abysmal and severely lacking, but he said we can use any language we feel more comfortable in. some are using VB others PHP and some in C ++.

	Heh... My college instructor at least understood most of the
available languages (the campus mainframe -- 1978 -- supported FORTRAN,
COBOL, Assembly, SNOBOL, BASIC, APL, and one or two others)... He once
gave an assignment with "... any language he knew" as a criteria. So...
He got it in at least three languages! The assignment was a "hashed head
multiple linked list" name/phone directory. I did it in BASIC (which got
fun as the BASIC only allowed 4 open data files at a time).
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#44578

FromChris Angelico <rosuav@gmail.com>
Date2013-05-01 14:37 +1000
Message-ID<mailman.1206.1367383063.3114.python-list@python.org>
In reply to#44575
On Wed, May 1, 2013 at 9:20 AM, Alex Norton <ayjayn1101@gmail.com> wrote:
> the teacher actually cant teach anything, he as the knowledge of Vb but his teaching methods are abysmal and severely lacking, but he said we can use any language we feel more comfortable in. some are using VB others PHP and some in C ++.

Quit the course and go study someplace else... I wouldn't want to be
in any course where people use VB and PHP to build GUIs!

ChrisA

[toc] | [prev] | [next] | [standalone]


#44586

FromAlex Norton <ayjayn1101@gmail.com>
Date2013-05-01 03:27 -0700
Message-ID<db69c379-f70c-4d70-989b-5dee6933d909@googlegroups.com>
In reply to#44578
On Wednesday, 1 May 2013 05:37:34 UTC+1, Chris Angelico  wrote:
> On Wed, May 1, 2013 at 9:20 AM, Alex Norton <ayjayn1101@gmail.com> wrote:
> 
> > the teacher actually cant teach anything, he as the knowledge of Vb but his teaching methods are abysmal and severely lacking, but he said we can use any language we feel more comfortable in. some are using VB others PHP and some in C ++.
> 
> 
> 
> Quit the course and go study someplace else... I wouldn't want to be
> 
> in any course where people use VB and PHP to build GUIs!
> 
> 
> 
> ChrisA

its a college course (Uk college btw) and its the last unit... im just gonna stick with it

python is quite easy ot understand (reading wise) that the teacher can attempt to read it with my comments

[toc] | [prev] | [next] | [standalone]


#44589

Fromjt@toerring.de (Jens Thoms Toerring)
Date2013-05-01 12:15 +0000
Message-ID<aucfb0F61jrU1@mid.uni-berlin.de>
In reply to#44575
Alex Norton <ayjayn1101@gmail.com> wrote:
> thanks... ill take a look at the Qt event handling

It's rather simple: instead of the program running through a
sequence of steps, the program normally is basically doing
nothing. It just reacts to events that normally come from
the user, i.e. the user clicks on some icon or widget, or
(s)he enters something via the keyboard. You etermine which
of all the possible events to which widget are relevant to
you, write handler functions for them and tell the widget
to call some function when an event happens. The simplest
case is a button: you want to react to it, so you write a
function for what's to be done when it's clicked on and
then tell Qt to call that function once it gets clicked
(there are different events even for a simple push button,
it can be clicked, just pushed, released etc.). And if you
have set up everything for that you tell Qt to start waiting
for events.

So the steps are:

  1. Tell Qt that this is a program using it

     app = QtGui.QApplication( sys.argv )

  2. Create your graphical interface (what you seem to
     have done more or less)

  3. Connect desired events (what's called "signals" in
     Qt lingo) for a certain widget to the function to be
     called with something like

     your_widget.clicked.connect( your_function )

     (replace 'clicked' with e.g. 'pushed' or 'released'
     when interested in a push or release signal instead)

  4. Start the event loop (i.e. have Qt wait for the user
     to do something and call one of your functions if the
     user did something you're interested in) with

     app.exec_( )

     When this returns the game is over.

So you don't wait for keyboard input with input() like in
your original program but instead tell Qt to do the waiting
for you and call the appropriate function you defined when
something interesting happens.

What you probably will have to change about the graphical
interface is that instead of using QLabel widgets for 'Air',
'Earth', 'Fire', 'Water' to use e.g. QPushButtons since
QLabels are rather static objects - they don't receive any
"click" events and it's rather likely some kind of event
like this is what you're going to want to react to. And for
that QPushButtons seem to be the simplest choice to start
with.

So have an 'Air' button (let's call it 'bAir' and then do

   bAir.clicked.connect( air_clicked )

after defining a function air_clicked() in which you deal
with that case. that might be as simple as

def air_clicked( ) :
	# Randomly pick one of 'air', 'fire', 'water' or 'earth'

    z = [ 'air', 'fire', 'water', earth' ][ random.randrange( 4 ) ]

	if z == 'air' :
        print( 'Stalemate' )
    elif z == 'water' :
        print( 'Air removes Water, you win!' )
    ...

Now, when during the game the 'Air' button is clicked this
function will get called.

Of course, it might be nicer to have a "result" label some-
where in the graphical interface which you set to the text
instead of printing it out to the console. And you also will
probably add some "Quit" button to end the game.

                              Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

[toc] | [prev] | [next] | [standalone]


#44605

FromAlex Norton <ayjayn1101@gmail.com>
Date2013-05-01 16:24 -0700
Message-ID<7f7c31dc-94cf-45d7-8556-a56d09293559@googlegroups.com>
In reply to#44589
Thank you very much for the specific detail. I have already done the signal for the finish button so that the app closes when clicked

[toc] | [prev] | [next] | [standalone]


#45089

FromAlex Norton <ayjayn1101@gmail.com>
Date2013-05-10 01:23 -0700
Message-ID<ca3b5132-73fa-452c-992f-94345793aa14@googlegroups.com>
In reply to#44589
On Wednesday, 1 May 2013 13:15:28 UTC+1, Jens Thoms Toerring  wrote:
> Alex Norton <ayjayn1101@gmail.com> wrote:
> 
> > thanks... ill take a look at the Qt event handling
> 
> 
> 
> It's rather simple: instead of the program running through a
> 
> sequence of steps, the program normally is basically doing
> 
> nothing. It just reacts to events that normally come from
> 
> the user, i.e. the user clicks on some icon or widget, or
> 
> (s)he enters something via the keyboard. You etermine which
> 
> of all the possible events to which widget are relevant to
> 
> you, write handler functions for them and tell the widget
> 
> to call some function when an event happens. The simplest
> 
> case is a button: you want to react to it, so you write a
> 
> function for what's to be done when it's clicked on and
> 
> then tell Qt to call that function once it gets clicked
> 
> (there are different events even for a simple push button,
> 
> it can be clicked, just pushed, released etc.). And if you
> 
> have set up everything for that you tell Qt to start waiting
> 
> for events.
> 
> 
> 
> So the steps are:
> 
> 
> 
>   1. Tell Qt that this is a program using it
> 
> 
> 
>      app = QtGui.QApplication( sys.argv )
> 
> 
> 
>   2. Create your graphical interface (what you seem to
> 
>      have done more or less)
> 
> 
> 
>   3. Connect desired events (what's called "signals" in
> 
>      Qt lingo) for a certain widget to the function to be
> 
>      called with something like
> 
> 
> 
>      your_widget.clicked.connect( your_function )
> 
> 
> 
>      (replace 'clicked' with e.g. 'pushed' or 'released'
> 
>      when interested in a push or release signal instead)
> 
> 
> 
>   4. Start the event loop (i.e. have Qt wait for the user
> 
>      to do something and call one of your functions if the
> 
>      user did something you're interested in) with
> 
> 
> 
>      app.exec_( )
> 
> 
> 
>      When this returns the game is over.
> 
> 
> 
> So you don't wait for keyboard input with input() like in
> 
> your original program but instead tell Qt to do the waiting
> 
> for you and call the appropriate function you defined when
> 
> something interesting happens.
> 
> 
> 
> What you probably will have to change about the graphical
> 
> interface is that instead of using QLabel widgets for 'Air',
> 
> 'Earth', 'Fire', 'Water' to use e.g. QPushButtons since
> 
> QLabels are rather static objects - they don't receive any
> 
> "click" events and it's rather likely some kind of event
> 
> like this is what you're going to want to react to. And for
> 
> that QPushButtons seem to be the simplest choice to start
> 
> with.
> 
> 
> 
> So have an 'Air' button (let's call it 'bAir' and then do
> 
> 
> 
>    bAir.clicked.connect( air_clicked )
> 
> 
> 
> after defining a function air_clicked() in which you deal
> 
> with that case. that might be as simple as
> 
> 
> 
> def air_clicked( ) :
> 
> 	# Randomly pick one of 'air', 'fire', 'water' or 'earth'
> 
> 
> 
>     z = [ 'air', 'fire', 'water', earth' ][ random.randrange( 4 ) ]
> 
> 
> 
> 	if z == 'air' :
> 
>         print( 'Stalemate' )
> 
>     elif z == 'water' :
> 
>         print( 'Air removes Water, you win!' )
> 
>     ...
> 
> 
> 
> Now, when during the game the 'Air' button is clicked this
> 
> function will get called.
> 
> 
> 
> Of course, it might be nicer to have a "result" label some-
> 
> where in the graphical interface which you set to the text
> 
> instead of printing it out to the console. And you also will
> 
> probably add some "Quit" button to end the game.
> 
> 
> 
>                               Regards, Jens
> 
> -- 
> 
>   \   Jens Thoms Toerring  ___      jt@toerring.de
> 
>    \__________________________      http://toerring.de

how would i go about adding print outcomes of all options  to a label ?

[toc] | [prev] | [next] | [standalone]


#45157

Fromjt@toerring.de (Jens Thoms Toerring)
Date2013-05-11 22:20 +0000
Message-ID<av7ugtF8ptkU1@mid.uni-berlin.de>
In reply to#45089
Alex Norton <ayjayn1101@gmail.com> wrote:
> On Wednesday, 1 May 2013 13:15:28 UTC+1, Jens Thoms Toerring  wrote:
> > Of course, it might be nicer to have a "result" label some-
> > where in the graphical interface which you set to the text
> > instead of printing it out to the console. And you also will
> > probably add some "Quit" button to end the game.
>
> how would i go about adding print outcomes of all options  to a label ?

If you have a QLabel you can set its text to anything you want
using its setText() method.
                                 Regaeds, Jens

PS: If I may ask you a favor: consider refraining from using Google's
    completely broken interface to newsgroups - your post consists
    of nearly 200 lines of text containing all I wrote, with an empty
    line inserted between each of them, and a single line of text
    you wrote. It's rather annoying to have to sieve through that
    much of unrelated stuff just to find thar one line that's re-
    levant. And this Google groups crap seems to make it nearly
    impossible to do it any other way. If you don't believe me see
    e.g.

      http://wiki.python.org/moin/GoogleGroupsPython

    There are much better alternatives to "Google groups",
    using a real usenet news server and a program that does
    not mess up content of news group postings. They've been
    developed with 30 years of experience with newsgroups.

    If I'd be conspiracy theorist I would conclude that Google
    is up to something bad in trying to make using newsgroups
    nearly impossible by their badly broken stuff (and, to add
    credibility to such a claim, their complete disregard for
    all the criticism they got over the years, actually making
    each version of Google groups even worse), but it's rather
    likely just another case of pure incompetence (or a "why
    should we care" attitude:-(
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

[toc] | [prev] | [next] | [standalone]


#45186

FromChris “Kwpolska” Warrick <kwpolska@gmail.com>
Date2013-05-12 17:59 +0200
Message-ID<mailman.1583.1368374425.3114.python-list@python.org>
In reply to#45157
(slightly offtopic, sorry.)

On Sun, May 12, 2013 at 12:20 AM, Jens Thoms Toerring <jt@toerring.de> wrote:
> PS: If I may ask you a favor: consider refraining from using Google's
>     completely broken interface to newsgroups - your post consists
>     of nearly 200 lines of text containing all I wrote, with an empty
>     line inserted between each of them, and a single line of text
>     you wrote. It's rather annoying to have to sieve through that
>     much of unrelated stuff just to find thar one line that's re-
>     levant.

Gmail automatically hides long quotes.  This is helpful in situations
like this one.  More mail software should implement that
functionality.  Seriously: once you go Gmail, you never go back.

>             And this Google groups crap seems to make it nearly
>     impossible to do it any other way. If you don't believe me see
>     e.g.
>
>       http://wiki.python.org/moin/GoogleGroupsPython
>
>     There are much better alternatives to "Google groups",
>     using a real usenet news server and a program that does
>     not mess up content of news group postings. They've been
>     developed with 30 years of experience with newsgroups.

Or something even better: a mailing list.
http://mail.python.org/mailman/listinfo/python-list is where you can
find it.  Much friendlier than Usenet, and the software itself is
developed by the FLUFL.

>     If I'd be conspiracy theorist I would conclude that Google
>     is up to something bad in trying to make using newsgroups
>     nearly impossible by their badly broken stuff (and, to add
>     credibility to such a claim, their complete disregard for
>     all the criticism they got over the years, actually making
>     each version of Google groups even worse), but it's rather
>     likely just another case of pure incompetence (or a "why
>     should we care" attitude:-(

They shouldn’t care because Usenet users often yell “Get off my
lawn!”.  Young people don’t use newsgroups.  They don’t even know what
Usenet is.

--
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail                | always bottom-post
http://asciiribbon.org        | http://caliburn.nl/topposting.html

[toc] | [prev] | [next] | [standalone]


#45204

Fromjt@toerring.de (Jens Thoms Toerring)
Date2013-05-12 21:56 +0000
Message-ID<avahgmFq455U1@mid.uni-berlin.de>
In reply to#45186
Chris “Kwpolska” Warrick <kwpolska@gmail.com> wrote:
> (slightly offtopic, sorry.)

> On Sun, May 12, 2013 at 12:20 AM, Jens Thoms Toerring <jt@toerring.de> wrote:
> > PS: If I may ask you a favor: consider refraining from using Google's
> >     completely broken interface to newsgroups - your post consists
> >     of nearly 200 lines of text containing all I wrote, with an empty
> >     line inserted between each of them, and a single line of text
> >     you wrote. It's rather annoying to have to sieve through that
> >     much of unrelated stuff just to find thar one line that's re-
> >     levant.

> Gmail automatically hides long quotes.  This is helpful in situations
> like this one.  More mail software should implement that
> functionality.  Seriously: once you go Gmail, you never go back.

i giess you mean Gougle groups and not Gmail, which I can't comment
on since I don't use it.

You still have to "un-hide" the message when you want to under-
stand what the other person is respoding to. And then you're back
to square one (and the double-spacing issue seems to remain). That
is why it has been a good tradition to remove everything when
you reply that isn't relevant to what you're replying to. Of
course, with the sorry excuse for an editor you habe in a web
based form that's more difficult to do than with a real editor.
That's one of the reasons I would advice to use a specialized
program that can be made to use the editor of your choice.

Another extremly annoying thing when reading via Google groups is
that there's no reasonable threading, i.e. it's not immediately
obvious what is meant as a reply to a specific post. That makes
Google groups basically useless for longer discussions.

And then Google groups overflow with spam messages that any
self-respecting news server would discard, so you never get
to see them.

> >             And this Google groups crap seems to make it nearly
> >     impossible to do it any other way. If you don't believe me see
> >     e.g.
> >
> >       http://wiki.python.org/moin/GoogleGroupsPython
> >
> >     There are much better alternatives to "Google groups",
> >     using a real usenet news server and a program that does
> >     not mess up content of news group postings. They've been
> >     developed with 30 years of experience with newsgroups.

> Or something even better: a mailing list.
> http://mail.python.org/mailman/listinfo/python-list is where you can
> find it.  Much friendlier than Usenet, and the software itself is
> developed by the FLUFL.

Mailing lists are quite fine and I'm on quite a number of them.
But I don't want many more to further fill up my inbox. And there
you again have the problem that there's no reasonable threading
of messages when these messages arrive in your mail folder.

> >     If I'd be conspiracy theorist I would conclude that Google
> >     is up to something bad in trying to make using newsgroups
> >     nearly impossible by their badly broken stuff (and, to add
> >     credibility to such a claim, their complete disregard for
> >     all the criticism they got over the years, actually making
> >     each version of Google groups even worse), but it's rather
> >     likely just another case of pure incompetence (or a "why
> >     should we care" attitude:-(

> They shouldn’t care because Usenet users often yell “Get off my
> lawn!”.  Young people don’t use newsgroups.  They don’t even know what
> Usenet is.

Well, it's a pity when younger people don't use newsgroups (no
idea if this is true, though) since they can be extremely useful
for all kinds of purposes - I e.g. learned a huge amount from
just lurking. And while some groups may be nicer than others,
that's no excuse for Google at all to actively trying to destroy
them. I'd rather prefer Google to simply get rid of Google groups
and put the long time archives they obtained from DajaNews into
better hands that do care.
                               Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

[toc] | [prev] | [next] | [standalone]


#45205

FromChris Angelico <rosuav@gmail.com>
Date2013-05-13 08:18 +1000
Message-ID<mailman.1599.1368397087.3114.python-list@python.org>
In reply to#45204
On Mon, May 13, 2013 at 7:56 AM, Jens Thoms Toerring <jt@toerring.de> wrote:
> Chris “Kwpolska” Warrick <kwpolska@gmail.com> wrote:
>> Gmail automatically hides long quotes.  This is helpful in situations
>> like this one.  More mail software should implement that
>> functionality.  Seriously: once you go Gmail, you never go back.
>
> i giess you mean Gougle groups and not Gmail, which I can't comment
> on since I don't use it.
>

No, Chris (not me, the other Chris... *an*other Chris.... okay, one of
the chorus of Chrises of this list!) did mean Gmail, the Google
webmail client. It does threading (and does it better than
SquirrelMail does), and it does the hiding of long quotes, long
signatures, etc.

ChrisA

[toc] | [prev] | [next] | [standalone]


#45206

Fromjt@toerring.de (Jens Thoms Toerring)
Date2013-05-12 22:58 +0000
Message-ID<aval4dFr96lU1@mid.uni-berlin.de>
In reply to#45205
Chris Angelico <rosuav@gmail.com> wrote:
> On Mon, May 13, 2013 at 7:56 AM, Jens Thoms Toerring <jt@toerring.de> wrote:
> > Chris “Kwpolska” Warrick <kwpolska@gmail.com> wrote:
> >> Gmail automatically hides long quotes.  This is helpful in situations
> >> like this one.  More mail software should implement that
> >> functionality.  Seriously: once you go Gmail, you never go back.
> >
> > i giess you mean Gougle groups and not Gmail, which I can't comment
> > on since I don't use it.

> No, Chris (not me, the other Chris... *an*other Chris.... okay, one of
> the chorus of Chrises of this list!) did mean Gmail, the Google
> webmail client. It does threading (and does it better than
> SquirrelMail does), and it does the hiding of long quotes, long
> signatures, etc.

Ok, sorry then about that - as I said I never have used Gmail
(and don't plan using it for other reasons than usability - and
then I would hardly consider anything with a web interface for a
text medium to be very usable;-). But, as far as I understand,
Gmail is about email, so I'm a bit at a loss to understand what
got this to do with news groups and Google groups (were the post
I originally was responing to according to the header seemed to
be coming from) that I intended this to be about?

                          Best regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

[toc] | [prev] | [next] | [standalone]


#45208

FromChris Angelico <rosuav@gmail.com>
Date2013-05-13 09:08 +1000
Message-ID<mailman.1601.1368400111.3114.python-list@python.org>
In reply to#45206
On Mon, May 13, 2013 at 8:58 AM, Jens Thoms Toerring <jt@toerring.de> wrote:
> Chris Angelico <rosuav@gmail.com> wrote:
>> On Mon, May 13, 2013 at 7:56 AM, Jens Thoms Toerring <jt@toerring.de> wrote:
>> > Chris “Kwpolska” Warrick <kwpolska@gmail.com> wrote:
>> >> Gmail automatically hides long quotes.  This is helpful in situations
>> >> like this one.  More mail software should implement that
>> >> functionality.  Seriously: once you go Gmail, you never go back.
>> >
>> > i giess you mean Gougle groups and not Gmail, which I can't comment
>> > on since I don't use it.
>
>> No, Chris (not me, the other Chris... *an*other Chris.... okay, one of
>> the chorus of Chrises of this list!) did mean Gmail, the Google
>> webmail client. It does threading (and does it better than
>> SquirrelMail does), and it does the hiding of long quotes, long
>> signatures, etc.
>
> Ok, sorry then about that - as I said I never have used Gmail
> (and don't plan using it for other reasons than usability - and
> then I would hardly consider anything with a web interface for a
> text medium to be very usable;-). But, as far as I understand,
> Gmail is about email, so I'm a bit at a loss to understand what
> got this to do with news groups and Google groups (were the post
> I originally was responing to according to the header seemed to
> be coming from) that I intended this to be about?

Since you can subscribe to the mailing list python-list@python.org and
get all of comp.lang.python (sans a pile of spam), you can read it as
a threaded mailing list instead of a newsgroup. It comes to pretty
much the same thing, so effectively you get your choice of technology.

ChrisA

[toc] | [prev] | [next] | [standalone]


#45216

FromChris Angelico <rosuav@gmail.com>
Date2013-05-13 10:51 +1000
Message-ID<mailman.1608.1368406307.3114.python-list@python.org>
In reply to#45204
On Mon, May 13, 2013 at 9:47 AM, Dennis Lee Bieber
<wlfraed@ix.netcom.com> wrote:
> On Mon, 13 May 2013 08:18:05 +1000, Chris Angelico <rosuav@gmail.com>
> declaimed the following in gmane.comp.python.general:
>
>>
>> No, Chris (not me, the other Chris... *an*other Chris.... okay, one of
>> the chorus of Chrises of this list!) did mean Gmail, the Google
>
>         Is that the accepted group noun? I'd think a "crisis of Chrises" is
> more alliterative...

That works too! I automatically went for "chorus" since I work in
theatre, but I like your version. What do the other Chrises think?

ChrisA

[toc] | [prev] | [next] | [standalone]


#45221

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-05-12 19:47 -0400
Message-ID<mailman.1607.1368402440.3114.python-list@python.org>
In reply to#45204
On Mon, 13 May 2013 08:18:05 +1000, Chris Angelico <rosuav@gmail.com>
declaimed the following in gmane.comp.python.general:

> 
> No, Chris (not me, the other Chris... *an*other Chris.... okay, one of
> the chorus of Chrises of this list!) did mean Gmail, the Google

	Is that the accepted group noun? I'd think a "crisis of Chrises" is
more alliterative...
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#45227

FromGregory Ewing <greg.ewing@canterbury.ac.nz>
Date2013-05-13 20:10 +1200
Message-ID<avblfmF36trU1@mid.individual.net>
In reply to#45221
Dennis Lee Bieber wrote:
> 	Is that the accepted group noun? I'd think a "crisis of Chrises" is
> more alliterative...

A "confusion of Chrises" might be more appropriate
in this case.

-- 
Greg

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.python


csiph-web