JoshuaBurleson 23 Posting Whiz

While I feel it's probably not necessary as some of the best code in the world is open source and have several other reservations about it, I'll still do the nice thing and answer your question. You could register your work with the U.S. Copyright Office if you wanted to be EXTREME about it http://www.ehow.com/how_5956351_change-copyright-exe-file.html


http://www.copyright.gov/

JoshuaBurleson 23 Posting Whiz

Python is a GREAT place to start. You can easily learn the fundamentals of programming with a powerful language that's almost as clear as English. It's been said, and I'm not saying I necessarily agree, that it would be possible to use only Python for anything you ever needed to program. Also as far as games go, Python has a great module/extension Pygame which makes building games a snap. I recommend checking out books like Python Programming for the absolute beginner "every chapter has a game", Head First Python "not really games but good books", and if you're up for some lighter reading then there's Invent Your Own Computer Games with Python, I haven't read it but it's designed for preteens-teens so it can't be too hard to learn from. Best of luck and happy coding!

JoshuaBurleson 23 Posting Whiz

I suggest befriending and/or joining a group of community sites or a community hub. For example many malls and outlet malls have their own facebook pages, if you're in or near that mall you should befriend it and post updates and info on there. Also, several small towns may have a community page, this can be used to your advantage with a simple reminder for your customers to "shop locally".

JoshuaBurleson 23 Posting Whiz

I've been on here for a few weeks now and I JUST found this CI forum, so let me apologize for the late start, "been too busy on Python". I'm a college student, but not in an IT field. Actually I've switched majors so many times it's ridiculous, Elementary Education, Criminal Justice, Social Work, Christian Ministry. I guess I just honestly don't know what I want to sit down and listen to crap about for four years. But I do love programming, I started a long time ago and then got annoyed by while loops and just put off picking it back up forever (didn't take failure well back then) but recently I picked it back up, not sure why, relearned what little I thought I knew and now, thanks to my perseverance and the help of the amazing people here at Daniweb, I dare say I'm doing pretty darn good for a beginner. I almost want to major in IT now, "although that both; is a contested field of study due to the ever changing nature of it, and I don't want to jinx something I really enjoy by majoring in it like all my other majors :D but hey, who knows. Anyways, thanks for all the help so far Daniweb, I can't wait to keep learning and help others out when I can.

kvprajapati commented: Hi! Welcome :) +0
JoshuaBurleson 23 Posting Whiz

12

JoshuaBurleson 23 Posting Whiz

and the resolution to that issue. Sorry to keep everybody so updated,

def searchfor(self):
        query=self.search.get().capitalize()
        self.search.delete(0,END)
        self.dict1={}
        for key in ab.book.keys():
            if query[0:2]==key[0:2]:
                query=key
                dict2={query:ab.book[query]}
                self.dict1.update(dict2)

        if len(self.dict1.keys())>1:
            for key in self.dict1.keys():
                Interface.result=key.title(),str(ab.book[key])
                for urlkey in urlinfo.keys():
                    if key==urlkey:
                        Interface.url=str(urlinfo[key])
                show()
        else:
            for key in ab.book.keys():
                if query[0:2]==key[0:2]:
                    query=key
                    Interface.result=query.title(),str(ab.book[query])
                    for urlkey in urlinfo.keys():
                        if query==urlkey:
                            Interface.url=str(urlinfo[query])
                    break
                else:
                    print('lies')
                    Interface.result='Query not found.'
            show()
JoshuaBurleson 23 Posting Whiz

however, as is this only works if there is more than one contact by the same name. Ohhh darn...

JoshuaBurleson 23 Posting Whiz

something like this seems to be working. It was smarter to use a dictionary. Don't know why I didn't think of it before, I guess sometimes you can get stuck in one way of thinking about a solution. Sometimes, especially in programming it seems, one must think outside of their own self-defined box. It looks MUCH better too.

def searchfor(self):
        query=self.search.get().capitalize()
        self.search.delete(0,END)
        self.dict1={}
        for key in ab.book.keys():
            if query[0:2]==key[0:2]:
                query=key
                dict2={query:ab.book[query]}
                self.dict1.update(dict2)
            else:
                Interface.result='Query not found.'
        if len(self.dict1.keys())>1:
            for key in self.dict1.keys():
                Interface.result=key.title,str(ab.book[key])
                show()
        else:
            show()
JoshuaBurleson 23 Posting Whiz

print(count) was just for me to see if other things were working correctly. Also, once Interface.result and Interface.url are set by the first then it stay the same for the second.

JoshuaBurleson 23 Posting Whiz

I've been working on getting tkinter to open a window for all dictionary items with keys matching a query. Below is a VERY RAW piece of code to show what I'm talking about. show() makes the toplevel windows. Also, not that it has so much going on because I isolate small sections of code to work on in seperate windows then copy and paste them into where they would go, then test and leave other things as comments so if something goes wrong I can temporarily revert back.

def searchfor(self):
        count=0
        list1=[]
        query=self.search.get().capitalize()
        for key in ab.book.keys():
            if query[0:2]==key[0:2]:
                count+=1
                print(count)
                list1.append(key)
                for items in list1:
                    Interface.result=query.capitalize(),str(ab.book[key])
                    show()
                    list1=[]          
##        for key in ab.book.keys():
            if query[0:2]==key[0:2]:
                query=key
                Interface.result=query.capitalize(),str(ab.book[query])
                show()
                break
            else:
                Interface.result='Query not found.'
                print(Interface.result)
        for key in urlinfo.keys():
            if query[0:2]==key[0:2]:
                query=key
                Interface.url=str(urlinfo[query])
                show()
                break

this causes there to be a duplicate window for one of them. Say I enter Josh and I have 2 Josh's, they both pop up, but one will have an extra window. Ideas?

JoshuaBurleson 23 Posting Whiz

I'm just going to start a new thread because this one could be very useful.

JoshuaBurleson 23 Posting Whiz

I tried creating a TopLevel with radio buttons for

for keys in ab.book.keys()
   if keys==query:
      somelist.append(keys)
if len(somelist)>1:
   instantiateToplevelwithradiobuttons()

obviously that's not verbatim

JoshuaBurleson 23 Posting Whiz

awesome, thanks. So I have a "not really" related question. I just hate flooding the board. I'm still working on the address book. If the user were to have more than one contact of the same name and they were to search for them, how would I make it possible for them to select which one they wanted? I'll show you the relevant code I have so far.

def searchfor(self):
        query=self.search.get().capitalize()
        if query in ab.book:
            Interface.result=query.capitalize(),str(ab.book[query])
        else:
            Interface.result='Query not found.'
        show()
'''-------------------------------------------'''
def show():
    showing=Toplevel()
    showing.title('Contact')
    showing.geometry('225x110')
    Display_contact(showing)

class Display_contact(Frame):
    '''Show a contact'''
    def __init__(self,master):
        super(Display_contact, self).__init__(master)
        self.grid()
        self.create_widget()

    def create_widget(self):
        self.contact=Label(self,text=''.join(Interface.result))
        self.contact.grid(row=1, column=3, columnspan=3)
        self.spacer=Label(self,text='   ')
        self.spacer.grid(row=0,column=0,rowspan=4,columnspan=3)
JoshuaBurleson 23 Posting Whiz

I meant how would I find a space and then a letter, and the str would be a variable, but I guess that doesn't really matter, that's just abstraction, and then how would I change that letter. Like if we had a two word string SA='Secret agent' and I wanted to .capitalize() agent.

JoshuaBurleson 23 Posting Whiz

I'm having a terrible time with regular expressions, possibly because I'm using a python2 reference, but maybe not. For example how would I find \s\w within a string and then change that character?

JoshuaBurleson 23 Posting Whiz

it might help to just show us the line of code you're talking about, to be honest it 176 lines is a bit much when you're talking about one section.

JoshuaBurleson 23 Posting Whiz

Is there a way to hide or at least automatically minimize the "shell-like" tkinter window, while running it?

JoshuaBurleson 23 Posting Whiz

honestly I'd package the python installer with it or a link to python with which version you're using, everybody has the Java runtime environment on their computer so having python shouldn't be a big deal.

JoshuaBurleson 23 Posting Whiz

utilizing modules like that may be a little above your "pay-grade" at the moment, I don't mean that offensively, I'd just stick with running the script. I'm not sure why you want to turn it into an .exe right now anyways, any reason?

JoshuaBurleson 23 Posting Whiz

never used PIL, but sounds legit. There you go @Thropian, get back to us with how it turns out.

JoshuaBurleson 23 Posting Whiz

8

JoshuaBurleson 23 Posting Whiz

Has anyone tried Microsoft's Python Tools for visual studio? I read on /. that it's suppose to support any interpreter not just Ironpython, but I'm only seeing Cpython and Ironpython. Any feedback?

http://pytools.codeplex.com/

JoshuaBurleson 23 Posting Whiz

Just so you know it's considered polite to mark the thread as solved so people can use it for future reference, and I'm sure pyTony wouldn't mind an upvote for his help if you feel it's in order.

JoshuaBurleson 23 Posting Whiz

it's an Acer Aspire One, I would love it if it wasn't for the charger port issue and the "broken" battery.

JoshuaBurleson 23 Posting Whiz

I haven't but I will now, thanks

JoshuaBurleson 23 Posting Whiz

pyTony, that does work.

import pickle
try:
    f=open('ABOOK.dat','rb+')
    adb=pickle.load(f)
    ab=AddressBook(adb)
except EOFError:
    f=open('ABOOK.dat','wb+')
    empdict={}
    pickle.dump(empdict,f)
    f.close()
    f=open('ABOOK.dat','rb+')
    adb=pickle.load(f)
    ab=AddressBook(adb)

Thanks, and that'll be good for future reference for others.

JoshuaBurleson 23 Posting Whiz

had it fixed for a moment. The answer for anybody with this problem in the future is to open it interactively, place something in it, and close it.

>>> import pickle
>>> pickle.dump({'Joshua':'Me'},f)
>>> f.close()

note that f was already assigned to open('filepath.extension','wb+')

but now, after truncating it to 0 by an error in the code again, this is not working...

JoshuaBurleson 23 Posting Whiz

I'm actually positive that happened size=0KB. rrrr. how do I fix this?

JoshuaBurleson 23 Posting Whiz

ABOOK.dat only contains a dictionary

JoshuaBurleson 23 Posting Whiz

thanks, I'll try that, but I can't at the moment because of a semi-related issue that, for unknown reasons just appeared.I'm getting this

Traceback (most recent call last):
  File "E:\AddressBook\abclass.py", line 103, in <module>
    adb=pickle.load(f)
EOFError

for this:

import pickle
f=open('ABOOK.dat','rb+')       
adb=pickle.load(f)
ab=AddressBook(adb)

idk what this is. Any idea why that would happen, especially when it was fine before?

JoshuaBurleson 23 Posting Whiz

oh, almost. I'm still getting the []

changed Label to: self.contact=Label(self,text=''.join(Interface.result))

just a reminder that it's originally this:

'Email: %s\n, Phone: %s\n, Address: %s' % (self.email.get(),self.phone.get(),self.adrs.get())
JoshuaBurleson 23 Posting Whiz

duh, of course... I'm very disappointed in myself. Thanks pyTony.

JoshuaBurleson 23 Posting Whiz

ugh, pardon my 1am grammar in the title

JoshuaBurleson 23 Posting Whiz

In version 3.0 of my address book I'm utilizing tkinter. The only problem thus far I'm having is that I have a very ugly display on a child window that shows the search result for a query. I'm getting

{Shoiukamp0@gmail.com[/email], Phone: (111)555-2222, Address: 122 C---- Ct., Essex, VT']}

The issue is that I'm looking for the text without the curly braces and list brackets, I tried substringing it but then nothing is displayed. Below are the segments of code related to this, note that searchfor for is a class method, also not that I'm aware that modifying the class attributes is not the best way to do this, but it worked best for me to make the child's label(this strategy is not my issue at hand).

def searchfor(self):
        query= self.search.get().capitalize()
        if query in ab.book:
            Interface.result=query.capitalize(),':',ab.book[query]
        else:
            Interface.result='Query not found.'
            print(Interface.result)
        show()

class Display_contact(Frame):
    '''Show a contact'''
    def __init__(self,master):
        super(Display_contact, self).__init__(master)
        self.grid()
        self.create_widget()

    def create_widget(self):
        self.contact=Label(self,text=Interface.result)
        self.contact.grid()

How could I go about making Interface.result ab.book[query] without the {[]}?
Thanks for the advice!

JoshuaBurleson 23 Posting Whiz

I figured it out. query needs to = self.search.get()

JoshuaBurleson 23 Posting Whiz

still having the issue. I printed the query so that it would show up in the IDLE shell and the query 'josh' = .46072912.46072880

JoshuaBurleson 23 Posting Whiz

I'm working on learning GUI development, I'm attempting to utilize the GUI for a user to search the dictionary: my code so far is

from tkinter import *

class Interface(Frame):
    def __init__(self, master):
        super(Interface, self).__init__(master)
        self.grid()
        self.create_widget()
        

    def create_widget(self):
        self.pwrd= Label(self, text='Address Book')
        self.pwrd.grid(row=0, column=2)
        self.searchlbl= Label(self, text='Enter Search Query:')
        self.searchlbl.grid(row=2, column=0)
        self.search= Entry(self)
        self.search.grid(row=2,column=1,columnspan=1)
        self.subsearch= Button(self, text='Submit', command=self.searchfor)
        self.subsearch.grid(row=2,column=2)
        self.searchresult= Text(self, width=40, height=10, wrap=WORD)
        self.searchresult.grid(row=3,column=0, columnspan=2, rowspan=2)

    def searchfor(self):
        query=str(self.search)
        self.searchresult.delete(0.0,END)
        if query in ab.book:
            result=ab.book[str(query)]
            self.searchresult.insert(0.0,result)
        else:
            result='Query not found.'
            self.searchresult.insert(0.0,result)

class AddressBook(object):
    """AddressBook Features"""
    def __init__(self, book):
        self.book=book

    def search(self,query):
        query=query.lower()
        if query in self.book:
            return self.book[query]



if __name__=='__main__':
    ab={'josh':'me'}
    ab=AddressBook(ab)
    root=Tk()
    root.title('Address Book')
    root.geometry('1500x800')
    Interface(root)
    root.mainloop()

regardless of the user input the Text displays 'Query not found', upon further examination I found that self.book became {{'josh':'me'}} why did it double the dictionary and is that why the search is being messed up?

JoshuaBurleson 23 Posting Whiz

First of all I would personally use pygame for that and livewires(just because) and I would think you'd need to have those parts of the image as separate images, place them on the frame so that they appear to be one image, then you could manipulate them as sprites individually.

JoshuaBurleson 23 Posting Whiz

are they files created by a module/program? Because if they are then why not just pickle them to a .dat file, load them in your module so you have the lists and use the "z = [item for item in x if item not in y]" idea?

JoshuaBurleson 23 Posting Whiz

@pyTony maybe you can help me, I was trying to utilize classes for this and it usually works but periodically I get the Error::

Traceback (most recent call last):
  File "E:\Cardgame\stuff.py", line 88, in <module>
    hand.total_check(hand.cards)
  File "E:\Cardgame\stuff.py", line 35, in total_check
    if card[0]=='J' or card[0]=='K' or card[0]=='Q':
TypeError: 'int' object is not subscriptable

The code so far is

suit=['c', 'd', 'h', 's']
vals=[2,3,4,5,6,7,8,9,10,'J','Q','K','A']
deck=[]
for st in suit:
    for val in vals:
        card=str(val)+str(st)
        deck.append(card)
import random
random.shuffle(deck)
hand=deck[0:2]
deck.pop(0)
deck.pop(0)
random.shuffle(deck)
class Hand(object):
    """A blackjack hand"""
    def __init__(self, cards, player,hand_val=0):
        self.cards=cards
        hand_val=0
        self.player=player
    """Check the value of the hand"""
    def recieve(self, card):
        self.cards.append(card)
        self.total_check(self.cards)
        
    def total_check(self, cards):
        self.hand_val=0
        for card in cards:
            card=str(card)
            if card[0] == 'A':
                card=11
                self.hand_val+=card
            if card[0]=='J' or card[0]=='K' or card[0]=='Q':
                card=10
                self.hand_val+=card
            else:
                card=int(card[0])
                if card==1:
                    card=10
                self.hand_val+=card
        if self.hand_val>21:
            self.bust()
        else:
            self.hit_or_stay()

    def bust(self):
        print(self.cards,'=',self.hand_val,'\n', self.player,'busted!')
       
    def hit_or_stay(self):
        print('\nCurrent hand:', self.cards,'=',self.hand_val)#remember that self.cards will show the strings A J K Q
        choice=input('Would you like to hit or stay?: ')
        choice=choice.lower()
        if choice=='hit':
            deck.give()
        else:#would not actually be my first choice but I'm trying to make a point
            print(self.hand_val)
            import random
            enemy=random.randint(16,21)
            if self.hand_val>enemy:
                print('Player:',self.hand_val,'\nComputer:',enemy,' Player Wins!')
            elif self.hand_val==enemy:
                print('Push')
            else:
                print('Player:',self.hand_val,'\nComputer:',enemy,' Computer Wins :(')
        

class Deck(object):
    def __init__(self, deck):
        self.deck=deck
    def give(self):
        togive=self.deck[0]
        self.deck.pop(0)
        hand.recieve(togive)
       
        

        
       
deck=Deck(deck)
name=input('Enter Your Name: ')
hand=Hand(hand,name)
hand.total_check(hand.cards)
JoshuaBurleson 23 Posting Whiz

oh I just realize I had '1' in the vals, is that why aces appeared doubled?

JoshuaBurleson 23 Posting Whiz

It's important to share the part of the code that you're asking for help on and related items. And are you trying to run those interactively or something? They worked fine for me.

JoshuaBurleson 23 Posting Whiz

my netbook is a piece of crap. The charger port has pushed in so far the charger needs to be held in, the battery is shotty and I need a new one. I respect the power of them however, and because they're so inexpensive they're great for tinkering around with the operating system(s) and great for checking cross-platform portability of programs.

JoshuaBurleson 23 Posting Whiz

@PyTony do you just write your code in the message body from your mobile or do you have an application for writing code on your mobile? Sorry to digress.

JoshuaBurleson 23 Posting Whiz

Perfect, thank you!

JoshuaBurleson 23 Posting Whiz

Without using classes, which would really make your project MUCH easier, you would need to remember to define the global variables in each function as I did below, start from there.

suit=['c', 'd', 'h', 's']
vals=[1,2,3,4,5,6,7,8,9,10,'J','Q','K','A']
deck=[]
deck2=[]
hand=''
def make_deck(deckname):
    global suit
    global vals
    for st in suit:
        for val in vals:
            card=str(val)+str(st)
            deckname.append(card)
make_deck(deck)
make_deck(deck2)
for card in deck2:
    deck.append(card)
import random
random.shuffle(deck)


def deal():
    global hand
    global deck
    dealt_cards=deck[0:2]
    hand=dealt_cards
    deck.pop(0)
    deck.pop(0)

def give(hand):
    global deck
    hit_card=deck[0]
    hand.append(hit_card)
    deck.pop(0)

"""You could test it with"""
print(hand,'\n')
deal()
print(hand)
print('')
give(hand)
print(hand)

It's important when starting a project as a beginner to remember that you may have done something that isn't compatible with your goal "which is why it's important to test your code very often during the process and understand the Error if one is thrown. Don't get caught up on what you already have, remember your goal and moreover remember that the real goal is learning, so that you really get the concept and what can and, likely will go wrong with it and how to fix it or work around it.

JoshuaBurleson 23 Posting Whiz

does it say how in the documentation? I tried that with an Entry(self) and when I tried stating if the variable I had assigned to it == F1 "how ever I hit the F1 button" nothing happened, it just wouldn't accept the input from the key "while writing the program, not user end."

JoshuaBurleson 23 Posting Whiz

I'm guessing the only way to do this is with some third party modules?

JoshuaBurleson 23 Posting Whiz

That helped a lot, thank you!

JoshuaBurleson 23 Posting Whiz

and I just realized there's a typo in my code from last night. It would be class Hand not class class hand.