Re: [Tutor] Shortening the code

2011-11-26 Thread Alan Gauld
On 26/11/11 16:16, Mic wrote: I will first post the entire program here, (not a lot of code) > and then ask the question. <---snipped ---> If you press the button in the first window, a new window open with all the “seats”. Say that you press one of the buttons so that it turns red. Then you

Re: [Tutor] Shortening the code

2011-11-26 Thread Peter Otten
Mic wrote: > text_file.close It has to be text_file.close() to actually do something. > text_file=open(self.filename,"w") > text_file.write(self.filename) > text_file.close() Pro-tip: this can be simplified to with open(self.filename, "w") as text_file: text_file.write(self.filename)

Re: [Tutor] Shortening the code

2011-11-26 Thread Mic
>IDLE sometimes slows things down and can occasionally lock >up with Tkinter (probably because it is itself written in Tkinter!). >It's usually better and faster to run Tkinter programs from a separate >console window. Okay, as a console window I assume the CMD terminal is OK? >What you a

Re: [Tutor] Shortening the code

2011-11-26 Thread ALAN GAULD
>> How are you running the code? > I am running it inside an IDLE. Does it matter IDLE sometimes slows things down and can occasionally lock up with Tkinter (probably because it is itself written in Tkinter!). It's usually better and faster to run Tkinter programs from a separate console wi

Re: [Tutor] Shortening the code

2011-11-26 Thread Mic
Alright! By the way, it seems like some people favour the use of pastebins, while others don?t, which is the way to go and why? I've stated my preference, Steven has stated his, so I guess you need to decide for yourself. However the best bet is not to paste long pieces of code at all, but s

Re: [Tutor] Shortening the code

2011-11-26 Thread Alan Gauld
On 26/11/11 12:52, Mic wrote: Alright! By the way, it seems like some people favour the use of pastebins, while others don’t, which is the way to go and why? I've stated my preference, Steven has stated his, so I guess you need to decide for yourself. However the best bet is not to paste long

Re: [Tutor] Shortening the code

2011-11-26 Thread Mic
>Not really, but a list can handle any kind of data, even functions, >objects etc (but they are all types of data too) >I was just being specific that I meant the list of data used to >configure your widgets. I should probably just have used its name! Alright! By the way, it seems like some peop

Re: [Tutor] Shortening the code

2011-11-26 Thread ALAN GAULD
> > and text in your data list and configure each button directly: > Is there any difference between a list and a data list? Not really, but a list can handle any kind of data, even functions, objects etc (but they are all types of data too) I was just being specific that I meant the list of data

Re: [Tutor] Shortening the code

2011-11-26 Thread Peter Otten
Mic wrote: [Alan Gauld] > >def create_widgets(self): > >list_chair=[(0, 0, '01'), (0, 1, '02'), > (0, 3, '03'), (0, 4, '04'), > (1, 0, '05')] > >for row, column, name in list_chair: > >command = partial(button_clicked, button) > >bu

Re: [Tutor] Shortening the code

2011-11-26 Thread Mic
Alright! What is a fixed argument? Its onre that is the same every time the function is called. The lambda construct above is equivalent to the following which may make it clearer: def button_clicked(aButton): # do something with aButton here # that uses a lot of code and

Re: [Tutor] Shortening the code of a finsihed program.

2011-11-25 Thread Alan Gauld
On 26/11/11 00:07, Steven D'Aprano wrote: Its usually better to paste long programs into a pastebin web site and give us a link. I'd just like to say that some of us disagree with this advice. Some people (e.g. me) often read their where getting access to a browser is less convenient. Its tr

Re: [Tutor] Shortening the code of a finsihed program.

2011-11-25 Thread Steven D'Aprano
Hello Mic, Mic wrote: Its usually better to paste long programs into a pastebin web site and give us a link. This saves cluttering up people mail with long messages, and also the pastebin rendering will usually be easier to read with syntax coloring etc. Please keep a attribution line when

Re: [Tutor] Shortening the code of a finsihed program.

2011-11-25 Thread Steven D'Aprano
Alan Gauld wrote: On 24/11/11 16:20, Mic wrote: and then try to put these parts togheter into a large program, I decided to post my entire program. Its usually better to paste long programs into a pastebin web site and give us a link. This saves cluttering up people mail with long messages,

Re: [Tutor] Shortening the code of a finsihed program.

2011-11-25 Thread Alan Gauld
On 25/11/11 21:14, Mic wrote: Alright. Sorry if I should know this, but what is a pastebin web site and how do I paste my program into a pastebin web site? A web site that you can paste stuff and then provide a link(url) that others can use to view it. You can usually specify the code style

Re: [Tutor] Shortening the code.

2011-11-25 Thread Alan Gauld
On 25/11/11 17:11, Mic wrote: for making a function that calls another function with a fixed argument is command = lambda button=button: button_clicked(button) Alright! What is a fixed argument? Its onre that is the same every time the function is called. The lambda construct above is eq

Re: [Tutor] Shortening the code of a finsihed program.

2011-11-25 Thread Mic
Its usually better to paste long programs into a pastebin web site and give us a link. This saves cluttering up people mail with long messages, and also the pastebin rendering will usually be easier to read with syntax coloring etc. Alright. Sorry if I should know this, but what is a pastebin

Re: [Tutor] Shortening the code.

2011-11-25 Thread Peter Otten
Mic wrote: > >> >from functools import partial > >>I use this kind of explicit import for a few names that I use frequently, >>namely defaultdict, contextmanager, everything from itertools... >>I think of these as my personal extended set of builtins ;) > >>As to the actual partial() function,

Re: [Tutor] Shortening the code.

2011-11-25 Thread Mic
>from functools import partial I use this kind of explicit import for a few names that I use frequently, namely defaultdict, contextmanager, everything from itertools... I think of these as my personal extended set of builtins ;) As to the actual partial() function, you probably don't see

Re: [Tutor] Shortening the code of a finsihed program.

2011-11-24 Thread Alan Gauld
On 24/11/11 16:20, Mic wrote: and then try to put these parts togheter into a large program, I decided to post my entire program. Its usually better to paste long programs into a pastebin web site and give us a link. This saves cluttering up people mail with long messages, and also the paste

[Tutor] Shortening the code of a finsihed program.

2011-11-24 Thread Mic
Good afternoon! I have previously asked questions about how I can shorten my code. I have recieved a lot of good answers, but there is one thing that never works. I can never implement the suggestions into my code, and that is my fault. I have in my previous questions only asked how to shorte

Re: [Tutor] Shortening the code

2011-11-22 Thread Asokan Pichai
On Wed, Nov 23, 2011 at 2:47 AM, Mic wrote: > [LOTS OF STUFF SNIPPED] >>> self.chair1.configure(bg="green") >>> os.remove ("Hamburg_Dortmund20_00") > >> And now you delete that file you created without having >> done anything with it? > > The meaning is that when the button is pressed once,  it ch

Re: [Tutor] Shortening the code

2011-11-22 Thread Mic
OK, So I'll guess you want a desktop program that eventually sends commands to an online service? If so thats a lot easier to do with Tkinter... :-) Well, it is enough if the program can run on my desktop. However, there are courses about learning how to make programs like these online, but I