Forum: Python 1 Day Ago |
| Replies: 15 Views: 261 sorry for the double post :)
here's another way by using radiobuttons instead:
from Tkinter import *
root = Tk(); root.geometry( "180x190+400+200" )
root[ "bg" ] = "white"
players = {... |
Forum: Python 1 Day Ago |
| Replies: 15 Views: 261 ok,
here's one ( not very good way of doing it ) but it'll give you some idea I hope. Since you haven't done classes I'll use functions and a dictionary for the players:
from Tkinter import *
... |
Forum: Python 2 Days Ago |
| Replies: 6 Views: 192 hi,
a couple of errors in your functions:
first, try to fix your indentation in the while loop, i.e. for the first if statement
second, the error occurs because you are calling the functions with... |
Forum: Python 3 Days Ago |
| Replies: 2 Views: 146 hi,
in order to clear the previous text you can use:
t = cv.create_text( .................. )
# do stuff
time.sleep( 1 )
cv.delete( t )
cv.update()
.delete(..) deletes the widget from the... |
Forum: Python 3 Days Ago |
| Replies: 1 Views: 133 well you could simply do this:
class Name:
def __init__( self, a, listOfValues ):
self.a = a
self.b = [ i for i in listOfValues ]
def main():
a = 5
# Generate... |
Forum: Python 3 Days Ago |
| Replies: 11 Views: 300 thanks a lot :) sry for the previous one - I'm still learning :) this one really is more readable.. |
Forum: Python 3 Days Ago |
| Replies: 11 Views: 300 hope this looks better :) |
Forum: Python 3 Days Ago |
| Replies: 11 Views: 300 @vegaseat
ok here goes :)
Well as you mentioned this works for Python2 though. I'll post the whole thing again but with the corrections included:
Dictionaries: |
Forum: Python 3 Days Ago |
| Replies: 11 Views: 300 I don't see the edit anymore it was there yesterday I think, so I cannot edit it :( all I see is quick reply... |
Forum: Python 3 Days Ago |
| Replies: 11 Views: 300 oh wait is there a way to actually change this? |
Forum: Python 3 Days Ago |
| Replies: 11 Views: 300 thanks the comment I'll try to modify it..... and of course avoid this next time :) |
Forum: Python 4 Days Ago |
| Replies: 14 Views: 365 of here's another way
d = { "a":4, "c":3, "b":12 }
newD = {}
# Reverse dictionary, i.e. becomes { 4:"a", 3:"c", 12:"b" }
for key in d:
newD[ d[ key ] ] = key
for v in sorted( d.values()... |
Forum: Python 4 Days Ago |
| Replies: 14 Views: 365 well you could do something like this:
d = { "a":4, "c":3, "b":12 }
for v in sorted( d.values() ):
for key in d:
if d[ key ] == v:
print key, v
break |
Forum: Python 4 Days Ago |
| Replies: 2 Views: 158 hi,
I recently created a fully working version of Minesweeper using Tkinter and I'll try to help you because it was rather hard to figure out the logic :) Here's my idea for all the buttons for the... |
Forum: Python 4 Days Ago |
| Replies: 3 Views: 160 Thanks a lot bro :)
It's really helpful. |
Forum: Python 4 Days Ago |
| Replies: 10 Views: 324 here's a more general version of this :) :
def population( start, maxPop, rate ):
start += ( ( float( rate ) / 100 ) * start )
year = 1
while start <= maxPop:
print year,... |
Forum: Python 5 Days Ago |
| Replies: 3 Views: 160 Found a solution :)
from Tkinter import *
def onclick():
pass
root = Tk()
text = Text(root)
text.insert(INSERT, "Hello.....") |
Forum: Python 5 Days Ago |
| Replies: 3 Views: 160 hi everyone,
I am trying to design an assembler program with Python using Tkinter and so far it is going pretty good. I just have one question: Is there anyway to change the text color of just a... |
Forum: Python 5 Days Ago |
| Replies: 9 Views: 278 well you need to decrease it by 1 because the output is
333
222
111
right? if you decrease it by 2 you'll get
333
111
if you don't decrease it at all you'll get an infinite, i.e never... |
Forum: Python 5 Days Ago |
| Replies: 10 Views: 270 well when you want to count stuff or find a sum of numbers you need the count, or whatever variable name you use, to be initially 0 because if it's 1 or more or 0 and less you will get incorrect... |
Forum: Python 5 Days Ago |
| Replies: 11 Views: 300 Here's a simple tutorial on dictionaries in Python:
Dictionaries:
Dictionaries are similar to other compound types except that they can use any immutable type as an index. One way to
create a... |
Forum: Python 5 Days Ago |
| Replies: 9 Views: 278 subtracts 1 from the value of count:
e.g.
>>>count = 3
>>>print count
3
>>>count = count - 1
>>>print count
2
>>> |
Forum: Python 5 Days Ago |
| Replies: 10 Views: 270 if you write the function like this:
def square( first, last ):
total = 0
for i in range( first, last + 1 ):
total = i**2 # Not total += i**2
return total
print square(... |
Forum: Python 5 Days Ago |
| Replies: 10 Views: 270 yes but at the end of the loop you would get 25 because the last value of i is 5, i.e. 5**2 = 25 so the value of total becomes 25 |
Forum: Python 5 Days Ago |
| Replies: 9 Views: 278 oki,
count is just a random variable to use in the while loop. Here I'm using it because the specification says that you want to print the numbers starting from n down to 1. Now if you decrease n... |
Forum: Python 5 Days Ago |
| Replies: 9 Views: 278 you need to convert i into string in order to display it n times, and I think a while loop is better here :)
def draw( n ):
count = n
while count > 0:
print str( count ) * n
... |
Forum: Python 5 Days Ago |
| Replies: 10 Views: 270 P.S.
probably the '+=' operation is confusing you here.... total += 1 simply means total = total + 1
:) |
Forum: Python 5 Days Ago |
| Replies: 10 Views: 270 right,
here's what happens here:
total holds the sum of all squared values, so the first time i = 3 so i**2 = 9, and total += i**2 means total = total + 9. The value for total here is 0 so... |
Forum: Python 5 Days Ago |
| Replies: 10 Views: 270 hi,
here's a way of doing it:
def square( first, last ):
total = 0
for i in range( first, last + 1 ):
total += i**2
return total
print square( 3, 5 ) |
Forum: Python 5 Days Ago |
| Replies: 4 Views: 252 right,
here's my version along with the licence stuff added. I'll try to explain what I'm doing with comments :)
cars = { "ABCD 123":"Mazda", "LFS 000":"Kia", "WINNR":"Ford", "XTRA":"Ford", "UR... |
Forum: Python 6 Days Ago |
| Replies: 6 Views: 217 :D sorry dude I was typing while you replied... |
Forum: Python 6 Days Ago |
| Replies: 6 Views: 217 hi,
here's a function to split the list in two equal halfs:
def half( l ):
mid = len( l ) / 2
a = l[ :mid ]
b = l[ mid: ]
return a, b |
Forum: Python 6 Days Ago |
| Replies: 4 Views: 252 hi
here's a hint how to create a new dictionary for the car makers:
cars = { "ABCD 123":"Mazda", "LFS 000":"Kia", "WINNR":"Ford", "XTRA":"Ford", "UR GR8":"Mazda" }
def build_car_maker( car ):... |
Forum: Python 6 Days Ago |
| Replies: 3 Views: 201 hi,
another way is to use the .strip() method like this:
>>> n = "sonya\n"
>>> print n
sonya
>>> a = n.strip()
>>>print a
sonya |
Forum: Python 7 Days Ago |
| Replies: 3 Views: 178 hi,
here's a small example on opening and reading from a file.
Suppose you have a file "data.dat" containing the numbers from 1 to 7 like this
1
2
3
4
5
6 |
Forum: Python 8 Days Ago |
| Replies: 1 Views: 239 hi,
here's my suggestion,
You can use a boolean variable, 'win' say, and initially set it to false. Then in you check function check to see if player one is victorious, if the check returns true,... |
Forum: Python 10 Days Ago |
| Replies: 11 Views: 305 hi,
you could do something like this:
f = open( "test.txt", "r" )
text = f.read()
f.close()
newText = ""
for each in text:
if each == ".": |
Forum: Python 10 Days Ago |
| Replies: 15 Views: 485 hi,
why don't you try to put your computation in the try block as well like this:
def turn_player1():
print 'Turn Player 1'
try:
columnchip = input( 'Column: ' )
if... |
Forum: Python 11 Days Ago |
| Replies: 2 Views: 254 hi,
I think the problem is here:
def ConvertToCAD(self):
# get text as string and convert it to float
money = float( self.entry.get() )
# do computation
money = money * 1.05
... |
Forum: Python 11 Days Ago |
| Replies: 15 Views: 485 P.S here's a sample of my output running the code:
>>>
Turn Player 1!
Which column?: 0
['.', '.', '.', '.']
['.', '.', '.', '.']
['.', '.', '.', '.']
['X', '.', '.', '.']
Turn Player 1! |