Gribouillis commented: interesting +14
sneekula 969 Nearly a Posting Maven
Peppermint tea with honey.
Boy in a letter to Santa: "Send me a baby brother."
Santa in a letter to boy: "Send me your mother."
News is often falsified on government orders, and the media seems to go along with it. That's too bad since a working democracy needs well informed, not missinformed, voters.
Draw a group of shapes on the Tkinter GUI toolkit canvas and animate the group using the common tag names.
From your error message I assume you are using the 32 bit version of Python 3.4
From
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil
download the Python version appropriate installer
Pillow‑2.6.1.win32‑py3.4.exe
Run this installer and see if the new installation fixes your problem.
You can try:
pre = "21:20:01 T:5796 NOTICE:"
for item in programList:
print("{} {}".format(pre, item))
A strictly C++ example for numeric input:
// enter a price of 0.0 or higher (positive value)
#include <iostream>
#include <limits>
int main()
{
float price = 0.0;
while ((std::cout << "Enter the price: ")
&& (!(std::cin >> price) || price < 0.0)) {
std::cout << "That's not a positive value! ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
std::cout << "You entered a price of " << price << "\n";
return 0;
}
Numeric input example (works with C or C++):
// a function to clean up the input of a real number
#include <stdio.h> // in/out function header
#include <ctype.h> // for isdigit()
#include <string.h> // for strlen()
#define EOS 0 // end of string marker
double real_in(void);
int main()
{
double db;
printf("\n Enter a mixed number eg. $12.45 (zero to exit): \n");
while(1) {
db = real_in();
printf("\n Numeric part of input = %f\n",db);
if (db == 0)
return 0;
}
getchar(); // wait
return 0;
}
// bulletproof entry of real numbers
double real_in(void)
{
static char s1[25], s2[25];
int k, n = 0;
printf("\n Enter a number : ");
gets(s1);
for (k = 0; k < strlen(s1); k++)
if (isdigit(s1[k]) || s1[k] == '.' || s1[k] == '-') {
s2[n] = s1[k];
n++;
}
s2[n] = EOS;
return (atof(s2)); // convert string to float
}
You can use input() for both versions of Python:
# Python2 uses raw_input() for strings
# Python3 uses input() for strings
# ----------------------------------------------
# add these few lines near the start of you code
import sys
# make string input work with Python2 or Python3
if sys.version_info[0] < 3:
input = raw_input
# ----------------------------------------------
# test ...
# now you can avoid using raw_input()
name = input("Enter your name: ")
# if you expect float input, use float() instead of int()
age = int(input("Enter your age: "))
print("%s you are %d old" % (name, age))
I simply searched
C:/Python27/Lib/lib-tk/Tkinter.py
or
C:/Python33/Lib/tkinter/init.py
for
clipboard
it's all fairly well documented
I actually needed to use it with a Tkinter program, so it came in handy.
You can accesss the clipboard simply by using the Tkinter GUI toolkit that comes with your Python installation.
How do you get a sweet little 80-year-old lady to say the F word?
Get another sweet little 80-year-old lady to yell “BINGO!”
"The scientific theory I like best is that the rings of Saturn are composed entirely of lost airline luggage."
-- Mark Russell
"Always borrow money from a pessimist. He won’t expect it back."
-- Oscar Wilde
According to nonprofitvote.org the voting turnout in the US is dependent on income, residency and age. The turnout is higher with more income, longer residency and older age.
I have seen that brand at Walmart.
Correctly typing in a 20 character jumbled password every time you turn on your computer, or want to access an account would be a royal pain. Most accounts kick you out after three tries, an essential security feature.
I like those small cubicles, you can decorate them to your likes.
In the Python forum you get down-votes because your solution works in version Python3 and not in the old Python2 version. What a mess that is.
This should give you a hint:
https://www.daniweb.com/software-development/python/threads/191210/python-gui-programming/12#post2131887
I guess doing the exercises in an online book like:
"Learn Python The Hard Way"
from:
http://learnpythonthehardway.org/book/
could be a project.
Explore the Tkinter GUI toolkit to draw a circle and move it with the arrow keys:
# use a Tkinter canvas to draw a circle, move it with the arrow keys
try:
# Python2
import Tkinter as tk
except ImportError:
# Python3
import tkinter as tk
class MyApp(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.title("move circle with arrow keys")
# create a canvas to draw on
self.cv = tk.Canvas(self, width=400, height=400, bg='white')
self.cv.grid()
# create a square box with upper left corner (x,y)
self.x = 120
self.y = 120
size = 150
box = (self.x, self.y, self.x + size, self.y + size)
# create a circle that fits the bounding box
self.circle = self.cv.create_oval(box, fill='red')
# bind arrow keys to movement
self.bind('<Up>', self.move_up)
self.bind('<Down>', self.move_down)
self.bind('<Left>', self.move_left)
self.bind('<Right>', self.move_right)
def move_up(self, event):
# move_increment is 5 pixels
y = -5
# move circle by increments x, y
self.cv.move(self.circle, 0, y)
def move_down(self, event):
y = 5
self.cv.move(self.circle, 0, y)
def move_left(self, event):
x = -5
self.cv.move(self.circle, x, 0)
def move_right(self, event):
x = 5
self.cv.move(self.circle, x, 0)
app = MyApp()
app.mainloop()
I could go for Rheinmetall Boxer.
Just waiting until the hybrid comes out.
Maybe Microsoft should think about Vindauga10.
The English word window originates from the Old Norse 'vindauga', from 'vindr – wind' and 'auga – eye'.
Try this:
''' wxBoxSizer101.py
button1 at upper right corner
button2 at lower right corner
'''
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, mytitle, mysize):
wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)
self.create_widgets()
def create_widgets(self):
self.button1 = wx.Button(self, wx.ID_ANY, label='Button1')
self.button2 = wx.Button(self, wx.ID_ANY, label='Button2')
# use a box sizer to lay out widgets
sizer_v = wx.BoxSizer(wx.VERTICAL)
# Add(widget, proportion, flag, border)
# border is to the left side
sizer_v.Add(self.button1, 0, flag=wx.LEFT, border=200)
# this adds a spacer (w, h)
# here only the height is important
sizer_v.Add((0, 200), proportion=0, flag=wx.EXPAND)
sizer_v.Add(self.button2, 0, flag=wx.LEFT, border=200)
self.SetSizer(sizer_v)
app = wx.App(0)
mytitle = "wx.BoxSizer Test101"
width = 300
height = 290
# create a MyFrame instance and show the frame
MyFrame(None, mytitle, (width, height)).Show()
app.MainLoop()
Toyota gives a factory warranty of 8 years for the Prius nickel hydride battery pack. The replacement past this period will cost you about $3,000. So, watch out when you buy an old used Prius.
A Toyota Prius battery, contains 168 1.2-Volt nickel-metal-hydride cells, which contain a total of 1.6 kilowatt-hours of energy. Its peak power output is 27 kilowatts, or about 36 horsepower.
Toyota had an awful lot of recalls lately. I almost got a used Prius until I read what a battery replacement would cost.
Maybe the improvement with Windows10 will be in security.
I would just temporarily convert back to a Python list:
import numpy as np
x = np.array([['t1',10,20],['t2',11,22],['t2',12,23], ['t3',21,32]])
print(x) # test
# convert temporarily to Python list again
mylist = x.tolist()
mylist2 = ['100', '101']
n = 0
newlist = []
for line in mylist:
if line[0] == 't2':
line[1] = mylist2[n]
n += 1
newlist.append(line)
print(newlist) # test
# convert back to numpy array
x = np.array(newlist)
print(x) # show result
There is also an error in line 12.
Since you are not running Python3 but Python2 tkinter should be Tkinter
Folks, this is the C forum.
No module named pk_DOMI
means that cx_Freeze can't find the mnodule, or you don't have it.
BTW, if you really want help don't hijack old solved posts. Most helpful folks won't look there for your problem. Start a new thread.
My 1997 Dodge Ram pickup truck still runs pretty well, but the rust is getting to it.
Works well, wonder why you need function translate()?
I have a tkinter program like the one below (for example) and want to create an executable file using module cx_freeze.
I am using Python33 and Windows7.
# Tk_circle2.py
# draw a circle with given center (x,y) and radius
# tkinter normally needs a specified square
try:
# Python2
import Tkinter as tk
except ImportError:
# Python3
import tkinter as tk
def get_center(x1, y1, x2, y2):
'''
for a rectangle with ulc=(x1,y1) and lrc=(x2,y2)
calculate the center (x,y)
'''
x = x1 + (x2 - x1)//2
y = y1 + (y2 - y1)//2
return x, y
def get_square(x, y, radius):
'''
given the center=(x,y) and radius
calculate the square for the circle to fit into
return x1, y1, x2, y2 of square's ulc=(x1,y1) and lrc=(x2,y2)
'''
x1 = x - radius
y1 = y - radius
x2 = x + radius
y2 = y + radius
return x1, y1, x2, y2
# create the basic window, let's call it 'root'
root = tk.Tk()
# create a canvas to draw on
cv = tk.Canvas(root, width=300, height=300, bg='white')
cv.grid()
# draw a circle with given center (x,y) and radius
x, y = 150, 120
radius = 65
# to draw a circle you need to get the ul and lr corner coordinates
# of a square that the circle will fit inside of
rect = get_square(x, y, radius)
# draw the cicle that fits into the rect/square
# default fill is canvas bg
#cv.create_oval(rect)
circle1 = cv.create_oval(rect, fill='red')
# optionally …
Explore the Tkinter GUI toolkit to draw a circle:
# draw a circle with given center (x,y) and radius
# tkinter normally needs a specified square
try:
# Python2
import Tkinter as tk
except ImportError:
# Python3
import tkinter as tk
def get_center(x1, y1, x2, y2):
'''
for a rectangle with ulc=(x1,y1) and lrc=(x2,y2)
calculate the center (x,y)
'''
x = x1 + (x2 - x1)//2
y = y1 + (y2 - y1)//2
return x, y
def get_square(x, y, radius):
'''
given the center=(x,y) and radius
calculate the square for the circle to fit into
return x1, y1, x2, y2 of square's ulc=(x1,y1) and lrc=(x2,y2)
'''
x1 = x - radius
y1 = y - radius
x2 = x + radius
y2 = y + radius
return x1, y1, x2, y2
# create the basic window, let's call it 'root'
root = tk.Tk()
# create a canvas to draw on
cv = tk.Canvas(root, width=300, height=300, bg='white')
cv.grid()
# draw a circle with given center (x,y) and radius
x, y = 150, 120
radius = 65
# to draw a circle you need to get the ul and lr corner coordinates
# of a square that the circle will fit inside of
rect = get_square(x, y, radius)
# draw the cicle that fits into the rect/square
# default fill is canvas bg
#cv.create_oval(rect)
circle1 = cv.create_oval(rect, fill='red')
# optionally show the recangle the circle fits into
cv.create_rectangle(rect)
# testing ...
print(get_square(x, y, radius)) # (10, 10, 90, 90)
print(get_center(*rect)) # …
Strange, pyserial has a class Serial()
Did you accidentally save your code file as serial.py?
Thanks, I got it to go!
''' pyg_Sound1.py
playing sound files using pyglet
download and install
pyglet-1.2alpha1.win32-py2.7.exe
from
http://www.lfd.uci.edu/~gohlke/pythonlibs/
avbin.dll is included
so pyglet can play .wav .mp3 .ogg sound files
(but not .mid Midi files)
'''
import pyglet
# pick a sound file you have, or one of those below
# in this case file names are case sensitive
#sound_file = 'drums.ogg'
#sound_file = 'cool_f.wav'
sound_file = 'Boing.mp3'
music = pyglet.media.load(sound_file)
music.play()
pyglet.app.run()
Python is case sensitive, so try:
ser = serial.Serial("COM5", 9600)
There used to be a Python module called pyglet that allowed graphics and sound. I can't find it anywhere.
Couldn't you simply do this:
digits = '234'
size = len(digits)
sum_odd = 0
for ix in range(1, size, 2):
sum_odd += int(digits[ix])
prod_even = 1
for ix in range(0, size, 2):
prod_even *= int(digits[ix])
print("sum of odd indexed integers = {}". format(sum_odd))
print("product of even indexed integers = {}". format(prod_even))
Thank y'all!
I guess I will go with the slicing example, since I don't need to pad.
I would like to break up a list into sublists of 3 elements each. I have this code, but it will give an index error when the length of the list is not divisible by 3.
mylist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
# groups of n
n = 3
newlist = []
for ix in range(n, len(mylist) + n, n):
sublist = [mylist[ix-3], mylist[ix-2], mylist[ix-1]]
#print(ix, sublist)
newlist.append(sublist)
print(newlist)
''' output -->
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]]
'''
Is there a better way to do this?
I seem to have a mental block!