lllllIllIlllI 178 Veteran Poster

Okay, you have to use your TextCtrl and then you have use something like:

t = wx.TextCtrl(arguments)
#... later
t.GetValue()

the GetValue() method fetches the current value of the textCtrl

lllllIllIlllI 178 Veteran Poster

You have a lot of errors your code. First of all let me say that you can really only use self when you are in a class. A lot of your code in your program should be in the __init__ method.

Also in you Add method you have return x as the first thing you say. This will stop the rest of the code from running. Instead it should be like:

def Add(self,event):
        
        y=input("")
        print x + y

Just dont worry about returning anything. You need not.

For your events you want wx.EVT_LEFT_DOWN to stimulate on a mouse click.

If fiddled around and this is what i got. It isnt perfect but it will help you along:

#!/usr/bin/python

# gridsizer.py

import wx

class GridSizer(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(300, 250))
        menubar = wx.MenuBar()
        file = wx.Menu()
        file.Append(0, '&Quit', 'Exit Calculator')
        menubar.Append(file, '&File')
        self.SetMenuBar(menubar)

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.display = wx.TextCtrl(self, -1, '',  style=wx.TE_RIGHT)
        sizer.Add(self.display, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 4)
        gs = wx.GridSizer(4, 4, 3, 3)
        self.e_but = wx.Button(self, 3, '=')
        self.e_but.Bind(wx.EVT_LEFT_DOWN, self.On)
        self.a_but = wx.Button(self, 2, '+')
        self.a_but.Bind(wx.EVT_LEFT_DOWN,self.Add)
    
        gs.AddMany([(self.e_but, 0, wx.EXPAND),(self.a_but, 0, wx.EXPAND)])
                       
                     
        sizer.Add(gs, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.Centre()
        self.Show(True)
    def On(self, event):
        x=input("")
        
    def Add(self,event):
        
        y=input("")
        print x + y



     
   
   
app = wx.App(False)
GridSizer(None, -1, 'GridSizer')
app.MainLoop()

Note that your program is not getting input from the GUI the input is still coming from the python console.

lllllIllIlllI 178 Veteran Poster

Okay. Im glad it works. Well done on fixing it yourself.

lllllIllIlllI 178 Veteran Poster

That means somewhere in your code. Perhaps in a bit that i cant see. There is a bit that makes balance not an int any more. So try and look for places where balance is changed.

lllllIllIlllI 178 Veteran Poster

Well this is working for me:

def process(balance):
    trans_type= raw_input("Enter Deposit(d), withdrawal(w), print(p), or quit(q):")
    amount=input("Enter the amount:")
    if amount<0:
        print"You've entered an invalid number."
    if trans_type=="d":
        balance= balance+amount
        print"Your current balance is", balance
    elif trans_type=="w":
        balance= balance-amount
        print"Your current balance is", balance
    return balance



def main():
    balance=5000
    restart=raw_input("Would you like to complete a transaction? (y/n):")
    while "y"==restart:
        balance = process(balance)



main()

I am doing all the things that you say you cant. I took out the changing it to an int with the int() function because it was doing nothing. Perhaps that did something. Try copy-paste my code.. see if it works on your computer.

lllllIllIlllI 178 Veteran Poster

Can you please give us examples of numbers which stuff up the program and the FULL error statement because that will help even more. Also tell us wether you are doing a withdrawal, deposit or something else at that time.

Oh and please wrap your code in code tags. I will do it for you this time

def process(balance):
    trans_type= raw_input("Enter Deposit(d), withdrawal(w), print(p), or quit(q):")
    amount=input("Enter the amount:")
    if amount<0:
        print"You've entered an invalid number."
    if trans_type=="d":
        balance=int(balance)+int(amount)
        print"Your current balance is", balance
    elif trans_type=="w":
        balance=int(balance)-int(amount)
        print"Your current balance is", balance
    return balance



def main():
    balance=5000
    restart=raw_input("Would you like to complete a transaction? (y/n):")
    while "y"==restart:
        balance = process(balance)



main()

Also notice at the while "y" == restart bit? That will never stop executing. Replace all of main with another main method like this:

def main()
    restart = raw_input("Would you like to complete a transaction? (y/n):")
    balance = 5000
    while restart == "y":
        balance = process(balance)
        restart = raw_input("Would you like to complete another transaction? (y/n):")
lllllIllIlllI 178 Veteran Poster

you can also use eval or exec on the text file if it was like this:

t = 1
variable2 = 10
string = 'hello'

if you had this in your program

f = open('variables.txt')
for line in f:
    eval(line)
    #or exec(line)

That will then set up all of your variables.
Hope that helps

lllllIllIlllI 178 Veteran Poster

Ah i have had this problem before. I found it really really useful to use Threading.
So maybe you could make a function or class that uses Threading and then you can have it wait for user input while the rest of the program goes its own way.

lllllIllIlllI 178 Veteran Poster

So i take it your making you own module and importing it right? Well if you import a module you can access its variables by going

module.variable

If you have imported the module then the module is global and therefore there is global access to the variable.

If that isnt it, would you mind clearing it up a bit, in more detail.

lllllIllIlllI 178 Veteran Poster

if you want to print a variable in the middle of a print statement there are two ways to do it.

grade = 0
print "Final grade is",grade,"out of 100"

OR

grade = 0 
print "Final grade is %i out of 100" %grade

Hope that helps.

lllllIllIlllI 178 Veteran Poster

Congradulations, you have done very well.
:)

lllllIllIlllI 178 Veteran Poster

Can i just say, it was my fault, i have an error in my code. Woops.
Please add

frame.Show(True)

just before the app.MainLoop() statement.

That will make the frame show.

Sorry for the error :P

lllllIllIlllI 178 Veteran Poster

If you want to run the whole thing in IDLE then go to where the program is located, right click it. Then choose Edit in IDLE.

If that option does not exsist then you can also open IDLE and the go File - Open and open your .py or .pyw file for editing.

To run it in IDLE once it is open press F5.

Hope that helps

lllllIllIlllI 178 Veteran Poster

No that dosent tell us anything. Because if you run it line by line an else statement is going to be invalid syntax because there is no if before it. What you should to is run the whole program in IDLE and then post the error you get.

lllllIllIlllI 178 Veteran Poster

try using wx.EVT_TEXT and bind it to the Rich Text control.

lllllIllIlllI 178 Veteran Poster

To add a user just open the username and password files in append mode (a) and then write a new username and password. Then they will be stored and available next time you run the program, or if you re-load the lists then straight away.

lllllIllIlllI 178 Veteran Poster

How are you doing it?
I mean have you changed your code now so it goes:

module.monster
#rather then before
monster

Because unless you go

from module import *

You have to tell the program what module it is in. The second method imports all that is inside the module so you wouldn't have to change a thing.

lllllIllIlllI 178 Veteran Poster

Ah thats an easy one. Look at the class demon. Okay, notice in the __init__ method you call monster.__init__? Well remember to close those brackets.

That should fix it.

lllllIllIlllI 178 Veteran Poster

Well daniweb is a pretty vast community right? People here live all around the world.

Well with the whole thing about fuel being hugely expensive all around the world i thought it would be good to see the price of fuel all around the world. So just post your location and the price of fuel.

For example:
Location: Newcastle Australia
price in Liters: $1.43 (AUS dollars)
prince in gallons: $5.41 (AUS dollars)

It will be interesting to see the price range in different places. :)

lllllIllIlllI 178 Veteran Poster

So do you want something like this?

password = open('passwords.txt')
#each line in passwords.txt will have another passwords
password_list = password.readlines()
guess = raw_input("Enter the password: ")
if guess in password_list:
    #print short story
else:
    print "wrong password, program exiting"
    raw_input()
    #raw_input is there so the user can see the message 
    #before the program closes
lllllIllIlllI 178 Veteran Poster

Well the problem is that in your text file you may have an empty line and therefore splitting it will give you a list with nothing in it and therefore if you try and acces the variable at location 0 there is nothing there.
A list index out of range means that the list is not large enough to have a value stored at that location.

Hope that clears it up.

lllllIllIlllI 178 Veteran Poster

You have no choice when it comes to ordering dictionaries. If you want it to print nicely then you CAN order gameTable.keys() . Here is how i would do it:

gameTable = {(-5,10):0,(-4,10):0,(-3,10):0,(-2,10):0,(-1,10):0,(0,10):0, (1,10):0, (2,10):0, (3,10):0, (4,10):0, (5,10):0, (-5,9):0, (-4,9):0, (-3,9):0, (-2,9):0, (-1,9):0, (0,9):0, (1,9):0, (2,9):0, (3,9):0, (4,9):0, (5,9):0, (-5,8):0, (-4,8):0, (-3,8):0, (-2,8):0, (-1,8):0, (0,8):0, (1,8):0, (2,8):0, (3,8):0, (4,8):0}
keys = gameTable.keys()
keys.sort()
for key in keys:
    print key
    print gameTable[key]

Hope that helps.

lllllIllIlllI 178 Veteran Poster

Maybe instead of randrange you could have a list of possible hit vaules. This way you could have zero in there only a few time and higher numbers in more.

Im glad to hear that it is working.

Oh also maybe another way to do it would to have a variable that is set at the max number of hits with no value and then every time there is a hit of zero the counter goes down, and then if the counter is at zero and the randrange gets zero then you could make it re-do it.

lllllIllIlllI 178 Veteran Poster

Yeah thats not quite it. That program get things like microsoft sam to read text. What i have is a program in which you speak to the computer.

My program however only has a small list of words that it is built to recognise. That is what i help with. I want it to be able to try and decypher what your voice says at all time, not just when you say a word or phrase that is in the list.

lllllIllIlllI 178 Veteran Poster

Hi everyone,
I have been fiddling around with a speech recognition program for a while now and i always had something that bothered me. Here is my code i have been using. It is the example code from code.activestate.com

from win32com.client import constants
import win32com.client
import pythoncom

"""Sample code for using the Microsoft Speech SDK 5.1 via COM in Python.
    Requires that the SDK be installed; it's a free download from
            http://microsoft.com/speech
    and that MakePy has been used on it (in PythonWin,
    select Tools | COM MakePy Utility | Microsoft Speech Object Library 5.1).

    After running this, then saying "One", "Two", "Three" or "Four" should
    display "You said One" etc on the console. The recognition can be a bit
    shaky at first until you've trained it (via the Speech entry in the Windows
    Control Panel."""


class SpeechRecognition:
    """ Initialize the speech recognition with the passed in list of words """
    def __init__(self, wordsToAdd):
        self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
        self.listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
        self.context = self.listener.CreateRecoContext()
        self.grammar = self.context.CreateGrammar()
        self.grammar.DictationSetState(0)
        self.wordsRule = self.grammar.Rules.Add("wordsRule",
                        constants.SRATopLevel + constants.SRADynamic, 0)
        self.wordsRule.Clear()
        [ self.wordsRule.InitialState.AddWordTransition(None, word) for word in wordsToAdd ]
        self.grammar.Rules.Commit()
        self.grammar.CmdSetRuleState("wordsRule", 1)
        self.grammar.Rules.Commit()
        self.eventHandler = ContextEvents(self.context)
        self.say("Started successfully")

    def say(self, phrase):
        self.speaker.Speak(phrase)


class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
    def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
        newResult = win32com.client.Dispatch(Result)
        print "You said: ",newResult.PhraseInfo.GetText()
    
if __name__=='__main__':
    wordsToAdd = [ "One", "Two", "Three", "Four" ]
    speechReco = SpeechRecognition(wordsToAdd)
    while 1:
        pythoncom.PumpWaitingMessages()

My problem is you always need to provide the words in which you want it to be able …

lllllIllIlllI 178 Veteran Poster

Well i can just say that it is not the code's fault. It runs of windows XP fine so i would have to say that the problem most likely lies in the installation of something or your operating system.

lllllIllIlllI 178 Veteran Poster

May i just say well don on the new code. It is a lot better then the old code and it is great you learnt from your old code and this new stuff is a lot better.
Well Done!

lllllIllIlllI 178 Veteran Poster

I just inserted this just before the print line statement:

lines.reverse()

Then when it prints it goes from largest to smallest.

Hope that helps

lllllIllIlllI 178 Veteran Poster

This was how vega did it:

import base64
jpgfile = "halloween3.jpg"
jpg_text = base64.encodestring(open(jpgfile,"rb").read())
print jpg_text

Hope that helps.

lllllIllIlllI 178 Veteran Poster

And you are sure that it is going to that if statement? If not then put a print statement in there with a message so you know when something has entered the if statement.

lllllIllIlllI 178 Veteran Poster

Planning is probably one of the best things you can do in a programming project. A lot of people when given a project will start typing straight away, i find that if i plan my code. Determine what features i want and work out how i am going to get them then i find the actual coding part a lot easier.

Im glad you liked it.

lllllIllIlllI 178 Veteran Poster

Okay, well if you have any question just post them. It is a good idea to also test code as you go. That way you dont end up with massive errors that you need to re-write your code for.

But good luck!

lllllIllIlllI 178 Veteran Poster

Okay, well at the moment there are so many errors that i really cant begin to start. I have spent about 20 minutes trying to get your code to work but there are lots of fundamental things you need to do. I will outline the changes you need to do so it will be easier for all of us to help you.

ONE:
Change all _init_ methods in ALL of your classes to __init__ methods, you need those extra underscores for it to run, notice you will get a few errors when you try and instantise them, thats fine, just remove the arguments. Look at the exception carefully, it can tell you a lot.

TWO

for self.damage in axe() and sword():

That just dosent work. You cant iterate over things like that, your going to have to work out something else.

THREE

if self.attack > troll.defense or orc.defense:

This dosent work either. Python checks if self.attack is more then troll.defence. If False then it checks the other requirement which is orc.defence but seeing nothing is being compared with it as long as it is not 0 then it is True and the if runs. Also you cant use classes like that. Instantise all classes!

FOUR
Think through things logically and fiddle around, try things for yourself and see how things go. If you are stumped and cant think of anything, google it. Then ask us if nothing works. We cant do everything.

…
lllllIllIlllI 178 Veteran Poster

Ah wait!! I found something wrong in your code!! Wow im amazed i didnt spot it before! You know your _init_ statement in player only has one _ when it needs two __. Replace _init_ with this __init__ . That should solve some major issues!

lllllIllIlllI 178 Veteran Poster

I noticed in your previous code for your attack function you did not have self in the arguments. Is that how it is now? If not make sure self is in the arguments/parameters, whatever they are called :P.

Perhaps maybe post an update of your code as it is now.

lllllIllIlllI 178 Veteran Poster

Okay, i think your problem here is that you are giving your class player all the attributes of monster but you forget to initialise monster. Try adding

Monster.__init__()

to your player class __init__ code. Then you can refer to anything from monster as self. So it would be self.defense rather then monster. Might cause some issues with conficting variable names, just fiddle around a bit with it.

lllllIllIlllI 178 Veteran Poster

Yeah i'm fed up with the bush administration and im really glad its going. I spent today watching the election and from here in Australia you get the general feel that people here would rather Obama in.

Here we have Kevin Rudd in and he is a pretty young guy with a lot of the same ideals for the world as Obama, addmitedly a lot more boring and less inspiring but nevertheless still spouting lots of change. I rekon it will be interseting to see how other world leader will warm to Obama once he is in. Cause i agree that the bush admin really treated other countries badly at some points. In Oz it was often portayed many times by cartoons and other things that John Howard was George Bushes dog to do his bidding. I hope that with senetor Obama comes a new age in American relations with the political world.

lllllIllIlllI 178 Veteran Poster

Well i think that you should declare things like the players attack in the __init__ statement of player and make sure that their variable names dont point to anything else such as a method or an already made variable. So for example you could put your attack in a variable called self.attack_points.

That way there are no other variables or methods called the same things as well as you would just replace the old self.weapon.attack with self.attack_points and everything would hopefully work a lot better.

lllllIllIlllI 178 Veteran Poster

That is because when you go self.weapon.attack it logically goes, well self.weapon is a function in the class and then it looks for the variable attack as part of the method weapon. This is a problem and you should change this.

I noticed a lot of the things that you are using in your code have not actually been declared. Make sure to declare all of your variables.

lllllIllIlllI 178 Veteran Poster

Again you need to create an instance of player so somewhere put this:

p = player()
#then when you want to attack
p.attack()

hope that helps.

lllllIllIlllI 178 Veteran Poster

You would use a GUI module such as wxPython to do it. As to not just give you the answer but to point you in the right direction here is a basic frame with one button on it.

import wx

app = wx.App(redirect=False)
frame = wx.Frame(None, wx.ID_ANY,title = "Example")
button = wx.Button(frame,wx.ID_ANY,label = "Click me... but nothing will happen")
app.MainLoop()

perhaps you could find out how to add that other button and for the image you might want to look at this code snippet:
http://www.daniweb.com/code/snippet654.html

If you have any question just post them. :)

lllllIllIlllI 178 Veteran Poster

You could just reverse your list at the end to sort it the other way around.

lllllIllIlllI 178 Veteran Poster

here is one i made that works:

f = open("test.txt","r")
text = f.readlines()
f.close()

lines = []
for line in text:
        s = line.split()
        for score in s:
            lines.append(int(score))
           
for line in range(1, len(lines)):
    key = lines[line]
    i = line - 1
    while (i >=0) and (lines[i] > key):
        lines[i+1] = lines[i]
        i = i - 1
    lines[i+1] = key

print lines
lllllIllIlllI 178 Veteran Poster

There are a few different sort methods you could use. One of which you can find here:
http://www.daniweb.com/forums/thread153427.html
This uses insertion sorting to sort a list of numbers. It should work for this as well.

lllllIllIlllI 178 Veteran Poster

Okay, well here is one i knocked together, it dosent let you win but it has a lot of the features you will need:

import random


def start():
    words = ['one','one','two','two','three','three',
             'four','four','five','five','six','six']
    d = {}
    random.shuffle(words)

    for index, word in enumerate(words):
        d[index] = word
    return d

def printboard(d,revealed):
    side = 1
    print "   1  2  3  4"
    print "A",
    for i,f in enumerate(d.keys()):
        if revealed[i]:
            print d[f],
        else:
            print '--',
        
        if (i+1)%4==0:
            
            if i==3:
                print
                print "B",

            elif i == 7:
                print
                print "C",
def guess(rev):
    values= {'a':0,
             'b':4,
             'c':8}
    row = raw_input("\nWhat row do you choose? (a,b,c)").lower()
    col = input("What column do you choose? (1,2,3,4)")
    row = values[row]
    total = row+col-1
    if rev[total]==True:
        rev[total]='already_guessed'
    else:
        rev[total] = True
    return rev, total

                
def Main():
    rev = [False for f in range(12)]
    d = start()
   
    
    while True:
        printboard(d,rev)
        rev, total = guess(rev)
        printboard(d,rev)
        rev, total2 = guess(rev)
        
        if d[total]==d[total2]:
            print "\nGreat you got one"
        else:
            printboard(d,rev)
            print "\nOh no, not this time"
            raw_input("enter to continue")

            
            if rev[total] == 'already_guessed':
                pass
            else:
                rev[total]=False
                
                
            if rev[total2] == 'already_guessed':
                pass
            else:
                rev[total2] = False
        
if __name__ == '__main__':
    Main()
lllllIllIlllI 178 Veteran Poster

How about making a program that will get your weather forecast for tomorrow?

You can use modules such as urllib2 and things like that to get the source code of your favourite web weather forecaster and then scrape off all of the html tags to leave you with your forecast for the next few days.

lllllIllIlllI 178 Veteran Poster

Is this what your talking about?

import random
count = input("How long shall the sequence be?")
seq = ''.join([random.choice('AGTC') for x in range(count)])
print "Length:",count
print ">",seq
lllllIllIlllI 178 Veteran Poster

Is there anything in the text file now?

Because if it opens it will normally open in read mode and if there is nothing in the text file then there would be no lines to print to screen.

lllllIllIlllI 178 Veteran Poster

Have a look at vega's code snippet on this:
http://www.daniweb.com/code/snippet393.html
I think it is what you want. Otherwise just explain exactly what you mean by storing it in a .py file.

lllllIllIlllI 178 Veteran Poster

Try putting an r before the string to make it a raw text and therefore you wont get suff ups due to escaped characters:

elif choice == 5:
    h = open(r"C:/Users/Dhylan/Documents/"+raw_input()+".txt")

Hope that helps, if not the please help us help you by posting the exact error you get.