Hello,

I would like to know if there is any wway to change the Title of an input box( Left Upper Corner).

Lets say we have the input box:
x= input("blah blah blah")

if we run that the title of the input box would be like "Python input" or something, isnt in ?

So how can I change that to something else?

Thank you for your time

In Tkinter is would just be
top.title("New Title")

Or use a Label and Entry box if you have several entries and want a separate title/label for each one.

Ah, you are using input, i.e. the console

x= input("blah blah blah")

then you would just print a line to get something more than "blah blah blah" to print

print("Python Input")
x= input("blah blah blah")

Edited 4 Years Ago by woooee

What graphics module are you using? In Tkinter, there is nothing called an input box. Rather there is a widget called an "entry". It has no title, but you can fit it with a "label". Likewise, pyGTK, has a "text" and "label". In non-GUI python, "input" is a command indicating that the user is expected to type text. There's no box and no title. So, maybe I'm just not getting something obvious about your question but I'm not.

In wxPython you can do:

import wx
app = wx.PySimpleApp()
dlg = wx.TextEntryDialog(None, 'This is the text', 'This is the title', '')
if dlg.ShowModal() == wx.ID_OK:
    val = dlg.GetValue()
dlg.Destroy()
print "You entered %s" % val

Hello, thanks for your reply.
Actually in the Uni course they just teach us that way I mentioned before, so I cant use any other way in my project.
So there is no way using the input("") method isnt it?

Thank you

Why would you not describe the task you have, what have you done, your ideas how you plan to do the rest of it? For example the test cases you have prepared for your coding.

Then we can give some ideas to get you going.

Well, my task is something like that but with different dimensions, colours, and shapes
http://www.youtube.com/watch?v=2382T2o_SNA

Lets say we have a list with colours. we asking the users for their prefered colours, if the colours are not in the list or the colour already existed in their selection, then the program askss the user for another colour, but on that input box I would like to change the Title of the inputbox from Python input to "Invalid Colour" and write something in the inputbox like "Colour not in the colour list or already existed in you selections"

Your input window is idle's shell window. There is an option to change the title of the shell window when you start idle. Start idle with

idle -t "Python input"

from a terminal.

Edited 4 Years Ago by Gribouillis

You don't have an input box, you are using the command line so you would just print the error message. You should be able to modify the code you posted on the other forum

while True:
    first_colour = input("Please enter your first valid colour: ")
    if first_colour in list_colours:
        break

    print("Some error message")        ##  added

although I would use a function and a loop to get the colors instead of the 4 separate input statements.

or already existed in you(r) selections

You do not test for this in the code you posted.

Edited 4 Years Ago by woooee

Hello, I made an attempt to create the colour part of my project, but when i give something wrong like pink that is not in the list or an already existed colour and the loop start running Im getting an error :

NameError: global name 'colour' is not defined

Whats going wrong with my code, maybe is something obvious but I cant see it.

Thank you

#This is the function in case of invalid colour or already existed colour
def invalidColour():
     colour = input('''Invalid Colour!
The colour you choose is invalid or already existed in you selection.
The colour must be red, blue, green or yellow, magenta, orange or cyan.
Please enter a valid colour: ''')
     return colour


def selection():
#We gonna ask the user to input 4 different colours, In case of invalid
#colour the window of input will be pop up again until it receive a valid one
    print("Enter four  colours of your choice (red, blue, green, yellow, magenta, orange and cyan")
    list_colours = ["red", "blue", "green", "yellow", "magenta", "orange", "cyan"]
    #colour 1
    while True:
        first_colour = input("Please enter your first valid colour: ")
        while first_colour not in list_colours:
         first_colour = invalidColour(colour)
        break

    #colour 2
    while True:
        second_colour = input("Please enter your second valid colour: ")
        while (second_colour not in list_colours) or (second_colour == first_colour):
         second_colour = invalidColour(colour)
        break

    #colour 3
    while True:
        third_colour = input("Please enter your third valid colour: ")
        while (third_colour not in list_colours) or (third_colour ==first_colour) or (third_colour==second_colour) :
         third_colour = invalidColour(colour)
        break

    #colour 4
    while True:
        fourth_colour = input("Please enter your fourth valid colour: ")
        while (fourth_colour not in list_colours) or  \
                (fourth_colour ==first_colour) or \
                (fourth_colour==second_colour) or \
                (fourth_colour == third_colour) :
         fourth_colour = invalidColour(colour)
        break

    return(first_colour, second_colour, third_colour, fourth_colour)

@woooee
How can I use a loop, lets say we using a for loop and we have the varibles first_colour, second_colour, third_colour, fourth_colour, how can I change the varibale each time? beacuse the coulrs should be added each time to different variable. Sorry if my explanations are not clear, I know my writting its a bit messy as my mind is the same right now.
I need to take some brakes.

As Tony said, use a list. This can be run as is as a test.

def selection(number, list_colours, choices):
    while True:
        print("\nValid choices are %s" % (", ".join(list_colours)))
        colour = input("Please enter your %s valid colour: " % (number))

        if (colour in list_colours) and (colour not in choices):
            list_colours.remove(colour)
            return colour, list_colours

        else:
            if colour not in list_colours:
                print("That is not a valid colour")
            if colour in choices:
                print("You have already chosen that colour")
            ## always prints
            print("Please make your selection again")

list_colours = ["red", "blue", "green", "yellow", "magenta", "orange", "cyan"]
choices = []
for number in ["first", "second", "third", "fourth"]:
    choice, list_colours = selection(number, list_colours, choices)
    choices.append(choice)

print ("Choices made list =", choices)

Hello again and thank you for your reply.
@woooee your code is really helpful and with some edits it can do the work on my project.

Edited 4 Years Ago by bobys

def main():
    # calls the getCoords() and get the width and height
    [width,height]=getCoords()

    list_colours = ["red", "blue", "green", "yellow", "magenta", "orange", "cyan"]
    choices = []*25
    for number in ["first", "second", "third", "fourth"]:
        choice, list_colours = selection(number, list_colours, choices)
        choices.append(choice)
    print ("Choices made list =", choices)

    start = Point(100, 0)
    colourNumber = 1
    win = GraphWin("Patchwork Sample", (width) * 100, (height) * 100)
    win.setBackground("white")
    for border in range(height):
        middle = 0 #Center
        colourNumber = colourNumber + 2
        start = Point(0, border * 100)
        shape1(win, choices[colourNumber], start)
        for middle in range(width ):
            colourNumber = colourNumber + 1
            start = Point(middle*100, start.getY())
            if border == 0 or middle == width - 2 or border == height - 1:
            #Here the program getting an error
                shape1(win, choices[colourNumber], start)
            else:
                shape2(win, choices[colourNumber], start)
    win.getMouse()
    win.close()

Hello , Im calling the selector function (the function that woooee wrote). the shape 1 above the shape1 that I marked you is running fine but there Im getting error. and code is the same shape1(win, choices[colourNumber], start).
Whats going wrong? I have marked you the point tha Im getting error. Thank you

I found the solution guys thanks for your help. I will let you know if I need something else (for sure :) )

Hello guys,
I would like to ask your help again,

well i have that piece of code that draw a patch of boats:

def shape2(win, colour, start):
    s1 = -35
    s2 = -15
    s3 = -10
    s4 = -5
    for j in range(3):
        b1 = 12
        b2 = 0
        b3 = 25
        b4 = 5
        b5 = 20
        s1 = s1 + 35
        s2 = s2 + 35
        s3 = s3 + 35
        s4 = s4 + 35
        for i in range(4):
            triangle = Polygon(Point(start.getX()+b1,start.getY()+s1),\
            Point(start.getX()+b2,start.getY()+s2),\
            Point(start.getX()+b3,start.getY()+s2))
            triangle.setFill(colour)
            triangle.draw(win)
            line = Line(Point(start.getX()+b1,start.getY()+s2),\
            Point(start.getX()+b1,start.getY()+s3))
            line.draw(win)
            boat = Polygon(Point(start.getX()+b2,start.getY()+s3),\
            Point(start.getX()+b3,start.getY()+s3),\
            Point(start.getX()+b5,start.getY()+s4),\
            Point(start.getX()+b4,start.getY()+s4))
            boat.draw(win)
            b1 = b1 + 25
            b2 = b2 + 25
            b3 = b3 + 25
            b4 = b4 + 25
            b5 = b5 + 25

I would like to rewrite it but with less variables. I cant think any other way. Is like my mind stuck with that way. I asked my teacher but he told me that If I use that Im gonna lose marks. Ι'm in a real cleft stick!

I'm guessing the problem is the redundant calls to getX() and getY(). You do the exact same things 10 times for each boat drawn. That means 120 calls for the 12 boats. Move the call outside the for loops and store the values in variables. Also, the relationship between the "b" variables is constant so you only need one, i.e. instead of b2 you can use b1-12. And similar for the "s" variables. I originally though that perhaps you were supposed to use clone and move, but that wouldn't save anything and may even consume more computer resources.

Thanks for you reply, I will try that with variables b and s. But I didn't get that:

Move the call outside the for loops and store the values in variables

What you mean by that?
Thank you

Doesnt matter any more, I read your reply again curfully and I understand you ment. I think my project is done. I just sent it to my teacher for a review and give me his reccomendations.
If I get positive feedback, I'll submit it.
Thank you guys for your help, especially you woooee!

This question has already been answered. Start a new discussion instead.