Comment by martineau on Tkinter understanding mainloop
Working links:Here you have something about the update function. Here about update_idletasks..
View ArticleComment by martineau on Tkinter - Updating Coordinates or Moving a Shape with...
@HWW: Nope — the OP is trying to move the subjecton the canvas. It is also untrue that calling mainloop() prevents things from updating — quite the contrary.
View ArticleComment by martineau on Can we convert a Python project (and not a string) to...
Several (most if not all) of the existing solutions for converting a Python programs into into .exes do so in such a way that Python doesn't have to be installed on target computers in order to run them.
View ArticleComment by martineau on Convert JSON table horizontally
It looks like what you want to do is transpose the data in the table — so search for that term.
View ArticleComment by martineau on Is there a way to make tkinter's optionmenu to wait...
tkinter programs are user event-driven, so the flow of control is not the same as it is under the procedural programming paradigm you are used to using. Unfortunately is is not something that can be...
View ArticleComment by martineau on read csv without using import csv
You forgot to include your attempt to solve this problem. Stack Overflow is not a code-writing nor a custom tutorial service.
View ArticleComment by martineau on Non-overriden abstract-static method does not throw...
@JanJanáček: Alternative constructors are usually implemented a classmethods.
View ArticleComment by martineau on Iterate through a list of 3 mil. JSON objects |...
Profile your script and see where it's spending most of it's time.
View ArticleComment by martineau on Find element in a list of dicts based on value
Wouldn't it also make more sense to write for user in user_list: as opposed to items?
View ArticleComment by martineau on how to import variable from class correctly
@kaan46: It's impossible to debug unseen code. If you have another question, post it separately and include the code.
View ArticleComment by martineau on Shuffle a dictionary and list in unison?
You are mistaken, dictionaries have had their order defined since Python 3.7.
View ArticleComment by martineau on Cannot access variables of an object - 'has no...
It's good to hear my answer helped and was worth the effort it took to make. Besides learning Python, you're also dealing with tkinter which has many of its own idiosyncrasies (and is poorly documented).
View ArticleComment by martineau on Create buttons from instances of a class
list_aux=Food.instances does not make a copy of Food.instances, it just gives it another name — this is why calling get_instance() changes it. Use list_aux=Food.instances.copy() to make a copy of the...
View ArticleAnswer by martineau for generating equal diagonal lines in PIL
You can do it by first generating an image of vertical lines like I showed you in my answer to your other question, rotating that by 45°, and then cropping it. To avoid having areas of black, you need...
View ArticleAnswer by martineau for How to stop/pause and restart the code using same...
Here's runnable code that illustrates how to do it. It uses several global variables to keep track of the current state of the slide show that the various functions use to determine what needs to be be...
View ArticleAnswer by martineau for Python command prompt executed the second command...
By default the Windows start command does not wait for the specified command to finish, so it's possible for the other command you want to execute to (randomly) start before the current working...
View ArticleAnswer by martineau for Drift management of JSON configurations by comparing...
I think this will do what you say you want. I used the dictionary flattening code in this answer with a small modification — I changed it to not concatenate the keys of parent dictionaries with those...
View ArticleAnswer by martineau for Pass a list to a function instead of user-input -...
You can do it by temporarily changing stdin which is where the input() function gets its data:from contextlib import contextmanagerfrom io import StringIOimport sys@contextmanagerdef...
View ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticlePython version
When I attempt to use a static method from within the body of the class, and define the static method using the built-in staticmethod function as a decorator, like this:class Klass(object):...
View ArticleAnswer by martineau for How do I force python to be reproducible?
If you're using the random module, you can force it to always generate the same sequence of pseudo-random values by initializing it with a call to the function random.seed() with a specific value.I...
View ArticleAnswer by martineau for How to import a csv-file into a data array?
Assuming the CSV file is delimited with commas, the simplest way using the csv module in Python 3 would probably be:import csvwith open('testfile.csv', newline='') as csvfile: data =...
View ArticleAnswer by martineau for Exceptions: How to display which function caused the...
Here's a generic way to do which uses the traceback.extract_tb() function to get a list of “pre-processed” stack trace entries which have a subset of what's in a TracebackException object in them from...
View Article