python-3.x

How to get a horizontal scrollbar in Tkinter?

限于喜欢 提交于 2021-02-19 04:08:45
问题 I'm learning Tkinter at the moment. From my book, I get the following code for producing a simple vertical scrollbar: from tkinter import * # Import tkinter class ScrollText: def __init__(self): window = Tk() # Create a window window.title("Scroll Text Demo") # Set title frame1 = Frame(window) frame1.pack() scrollbar = Scrollbar(frame1) scrollbar.pack(side = RIGHT, fill = Y) text = Text(frame1, width = 40, height = 10, wrap = WORD, yscrollcommand = scrollbar.set) text.pack() scrollbar.config

pyinstaller and loading pickle file

落爺英雄遲暮 提交于 2021-02-19 03:56:07
问题 Has anyone worked with pyinstaller to create windows executables from python scripts? I'm trying to create an executable that loads a pickle file but not successful. import pickle filename='test.sav' try: model = pickle.load(open(filename, 'rb')) print('model loaded') except: print('An error occurred.') When run with python 3, it works and loads the model correctly but when run with the executable created by pyinstaller , it will through an exception. Help appreciated. 回答1: Im using kivy with

Circle Piping to and from 2 Python Subprocesses

邮差的信 提交于 2021-02-19 03:53:08
问题 I needed help regarding the subprocess module. This question might sound repeated, and I have seen a number of articles related to it in a number of ways. But even so I am unable to solve my problem. It goes as follows: I have a C program 2.c it's contents are as follows: #include<stdio.h> int main() { int a; scanf("%d",&a); while(1) { if(a==0) //Specific case for the first input { printf("%d\n",(a+1)); break; } scanf("%d",&a); printf("%d\n",a); } return 0; } I need to write a python script

relative position and content of namespace packages in Python >= 3.3

拜拜、爱过 提交于 2021-02-19 03:48:45
问题 I read the docs and quite some stackoverflow posts, but did not find an explicit answer to my doubts. I think I understand what namespace packages are for. I am only interested in Python>=3.3 and the implicit namespace packages - folders without the __init__.py . Questions Are namespace packages supposed to contain only other packages, or modules (i.e. .py files) are also "allowed"? Are namespace packages supposed to be used only as "container" packages, or can they also be contained in

upgrading default python version or install another python version in Linux

断了今生、忘了曾经 提交于 2021-02-19 03:47:28
问题 I want to upgrade python's default version i.e /usr/bin/python in Linux. I have multiple python versions installed as /usr/bin/python2.7 /usr/bin/python3.3 However, python command still returns python2.7 # python Python 2.7 Type "help", "copyright", "credits" or "license" for more information. >>> Now, I have installed a module, which got installed in the default version 2.7 . That's why I can't use python3.3 script.py , as it returns error for missing module. How to update this default

Change real camera resolution in OpenCV

天大地大妈咪最大 提交于 2021-02-19 03:40:19
问题 I'm trying to take 4k pictures using OpenCV, but when I change the resolution, the pictures just look resized instead of better quality. I'm using OpenCV version 4, Python 3.6, Logitech BRIO 4k webcam and Windows 10. If I don't change the camera resolution, it defaults to 640 x 480. If I change the resolution, the pictures just look blurred like they have been resized and not actually better quality. I can use the "Camera" app on Windows 10 to verify that the camera works with 4k resolution.

How can I save an object containing keras models?

情到浓时终转凉″ 提交于 2021-02-19 03:33:07
问题 Here is my code skeleton: def build_model(x, y): model = tf.keras.models.Sequential() model.add(tf.keras.layers.Dense(1, activation='relu')) model.compile(loss='mean_squared_error', optimizer='adam') model.fit(x, y) return model class MultiModel(object): def __init__(self, x1, y1, x2, y2): self.model1 = build_model(x1, y1) self.model2 = build_model(x2, y2) if __name__ == '__main__': # code that builds x1, x2, y1, y2 mm = MultiModel(x1, y1, x2, y2) # How to save mm ? The issue is I don't know

List comprehension iterate two variables at the same time [duplicate]

拈花ヽ惹草 提交于 2021-02-19 03:19:38
问题 This question already has answers here : How to iterate through two lists in parallel? (7 answers) Closed 4 years ago . Is it possible that with the use of list comprehension to iterate through two variables at the same time increasing the loop position in both at the same time. See example below: a = [1,2,3,4,5] b = [6,7,8,9,10] c = [i+j for i in a for j in b] # This works but the output is not what it would be expected. expected output is c = [7, 9, 11, 13, 15] (n'th element from a + n'th

Change grid size of a netCDF file

折月煮酒 提交于 2021-02-19 03:19:19
问题 Let's assume I have 2 netCDF data files with data for the same region (like South America, Africa, etc) but the different grid sizes as 0.5 degrees x 0.5 degrees and 1.0 degrees x 1.0 degrees in another. I want to increase or decrease its grid size to a different value such as 0.25 x 0.25 or 1.0 x 1.0 so that I can use this easily for raster calculations and comparison, etc. Is there a method to do this using any bash script, CDO, etc. A sample data can be downloaded from here. https://www

List comprehension iterate two variables at the same time [duplicate]

戏子无情 提交于 2021-02-19 03:19:15
问题 This question already has answers here : How to iterate through two lists in parallel? (7 answers) Closed 4 years ago . Is it possible that with the use of list comprehension to iterate through two variables at the same time increasing the loop position in both at the same time. See example below: a = [1,2,3,4,5] b = [6,7,8,9,10] c = [i+j for i in a for j in b] # This works but the output is not what it would be expected. expected output is c = [7, 9, 11, 13, 15] (n'th element from a + n'th