Quantcast
Channel: User martineau - Stack Overflow
Browsing all 44 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

Answer by martineau for Gaps In Grid Spaces - TKInter

There are different ways to get widgets to align in Tkinter when using the grid() layout-manager. For two widgets on the same row, the first could be given the sticky=E option and the following one...

View Article


Image may be NSFW.
Clik here to view.

Answer by martineau for tkinter grid method not properly placing the button

As others have pointed out in comments, rows and columns with nothing in them take up no space, and the only gridded widget you have is a custom Button at position row=250, column=250.You can change...

View Article


Answer by martineau for Using function to minimize the amount of code

The reason you need so much code is due to the way you're storing the information — namely differently named variables for each one — requires writing code specific to each one of them. To truly...

View Article

Answer by martineau for How do you get the name of the program using argparse?

ArgumentParser instances have a prog attribute which I think is what you want.import argparseparser = argparse.ArgumentParser()print('parser.prog: {}'.format(parser.prog))I discovered this by reading...

View Article

Answer by martineau for Trying to use multiprocessing queue but unable to get...

The while loop you have in your code is wrong because you don't want the function_to_get_from_q() process to quit everytime it checks the queue and it's empty. In the code below, a special value is...

View Article


Answer by martineau for Change value in nested JSON string

While it certainly could be accomplished via recursion given the nature of the problem, I think there's an even more elegant approach based on an idea I got a long time ago reading @Mike Brennan’s...

View Article

Image may be NSFW.
Clik here to view.

Answer by martineau for How to add a specific spacing in pixels between...

Using a specific number of pixels of spacing between each Buttondoesn't sound to me like such as good idea because it isn't very flexible nor easily portable to devices with different...

View Article

Answer by martineau for Create a nested dictionary with multipe dictionaries

I also think that using dictionary comprehensions is the best way to to solve this problem — but think it can be done in a more readable and flexible manner, like so:countries = {'Portugal', 'US'}score...

View Article


Answer by martineau for How to pass Python variable into bash commands?

You can use a so-called "f-string" to replace the variable references with their values.context = {'nickname': 'foobar'}bash_code = f'''echo "/common_home/{context['nickname']}...

View Article


Answer by martineau for tkinter: How can I remove labels created by for loops?

You can do it by taking advantage of the fact that the tkinter grid geometry manager, keeps track of the row and column location of all the widgets under its control. This means you can get the...

View Article

Answer by martineau for How to sort the output of difference between two sets?

You can sort the output by supplying a function via a keyword argument named key= to extract a comparison key from elements when calling the built-in sorted() function. In thus case all the callback...

View Article

Answer by martineau for Skipping lines, csv.DictReader

You could wrap the CSVFile with an itertools.islice iterator object to slice-off the lines of the preface when creating the DictReader, instead of providing it directly to the constructor.This works...

View Article

Image may be NSFW.
Clik here to view.

Answer by martineau for How to show images in a Listbox in tkinter?

As someone mentioned in a comment you can't put images in a Listbox, but as I mentioned in another, you could use a Text widget instead because you can put images into them. Below is a relatively...

View Article


Answer by martineau for How to control parallel processes with condition

I suggest using a multiprocessing.pool.Pool to limit the number of processes that are run concurrently (since you have indicated there might be a very large number of them).If you use its apply_async()...

View Article

Answer by martineau for Tkinter - Updating Coordinates or Moving a Shape with...

The way you're using mainloop() is wrong — it's typically only called once in a tkinter application because it is the loop that drives the whole GUI which is event-driven.One way to work around that...

View Article


Answer by martineau for Saving files to different folder

You can ensure the save folder exists by adding this line before the outer for loop:Path(save_path).mkdir(exist_ok=True)See documentation.

View Article

Answer by martineau for How to filter list of items based on substring?

I would suggest using the pathlib module which makes it easy to actually check the file's extension — which is a more rigorous test than merely whether the one string is a substring of another:from...

View Article


Image may be NSFW.
Clik here to view.

Answer by martineau for left align text on setting Label width

You need to specify an anchor option when creating the Label widget:from tkinter import *popup = Tk()Label(popup, text="Testing", width=25, anchor="w").grid( row=1, column=1, sticky="w", padx=(0,10),...

View Article

Answer by martineau for Shuffle a dictionary and list in unison?

Since test_list simply contains the values in test_dict, you can shuffle it and then recreate the former from the results of the latter.Note that if this correspondence between the two variables...

View Article

Answer by martineau for I want to calculate the difference between two values...

You say you want all permutations without any city to appearing twice, yet your example has the starting city (cityA) listed again at the end:I want for example: cityA-cityB + cityB-cityC +...

View Article
Browsing all 44 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>