Monday, March 30, 2020

queue in python language

from threading import *
import time
import random
import queue

def produce(q):
    while True:
        item=random.randint(1,100)
        print("producer producing item",item)
        q.put(item)
        print("producer giving notification")
        time.sleep(5)

def consume(q):
    while True:
        print("consumer waiting for updation")
        print("consumer consuming items:",q.get())
        time.sleep(5)
     

q=queue.Queue()
t1=Thread(target=consume,args=(q,))
t2=Thread(target=produce,args=(q,))
t1.start()
t2.start()


example 2:

import queue
q=queue.Queue()#FIFO
q.put(10)
q.put(20)
q.put(15)
q.put(30)
q.put(0)
while not q.empty():
    print(q.get(),end=' ')

output:
10 20 15 30 0

example 3:

import queue
q=queue.LifoQueue()
q.put(10)
q.put(20)
q.put(15)
q.put(30)
q.put(0)
while not q.empty():
    print(q.get(),end=' ')

output:
0 30 15 20 10


example 3:
import queue
q=queue.PriorityQueue()
q.put(10)
q.put(20)
q.put(15)
q.put(30)
q.put(0)
while not q.empty():
    print(q.get(),end=' ')

output:
0 10 15 20 30



Related links
shallow copy

Deep copy in python language

import copy

l1=[10,20,[30,40],50]
#l2=l1.copy()
#it dnot work for list inside another list
l2=copy.deepcopy(l1)

l2[2][0]=70
print("l2:",l2)
print("l1:",l1)

output:
l2: [10, 20, [70, 40], 50]
l1: [10, 20, [30, 40], 50]



related links:

shallow copy in python

shallow copy in python


l1=[10,20,30,40]
l2=l1
l2[2]=70
print("l2:",l2)
print("l1:",l1)

output:
l2: [10, 20, 70, 40]
l1: [10, 20, 70, 40]

example 2:

l1=[10,20,30,40]
l2=l1.copy()

l2[2]=70
print("l2:",l2)
print("l1:",l1)

output:
l2: [10, 20, 70, 40]
l1: [10, 20, 30, 40]

example 3:

import copy

l1=[10,20,[30,40],50]
#l2=l1.copy()
#it dnot work for list inside another list
l2=copy.copy(l1)

l2[2][0]=70
print("l2:",l2)
print("l1:",l1)

output:
l2: [10, 20, [70, 40], 50]
l1: [10, 20, [70, 40], 50]

Sunday, March 29, 2020

labels and colors of the plot of matplotlib in datascience using python

from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np

axes = plt.axes()
axes.set_xlim([-5,5])
axes.set_ylim([0,1.0])
axes.set_xticks([-5,-4,-3,-2,-1,0,1,2,3,4,5])
axes.set_yticks([0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0])
axes.grid()
plt.xlabel('Greebles')
plt.ylabel('Probility')
plt.plot(x, norm.pdf(x),'b-')
plt.plot(x,norm.pdf(x, 1.0, 0.5), 'g:')
plt.legend(['Sneetches','Gacks'],loc=4)

plt.savefig('C:\\Users\\Onyx1\\Pictures\\matplotlib\\matplot_lables.jpg', format='jpg')
plt.show()

output:

change line types and colors of the plot of matplotlib library in datascience using python

from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np

axes = plt.axes()
axes.set_xlim([-5,5])
axes.set_ylim([0,1.0])
axes.set_xticks([-5,-4,-3,-2,-1,0,1,2,3,4,5])
axes.set_yticks([0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0])
axes.grid()
plt.plot(x, norm.pdf(x),'b-')
plt.plot(x,norm.pdf(x, 1.0, 0.5), 'g:')

plt.savefig('C:\\Users\\Onyx1\\Pictures\\matplotlib\\matplot_x_y_ticks_bg_grid.jpg', format='jpg')
plt.show()

output:

back ground grid for plots in matplotlib in datascience using python

from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np

axes = plt.axes()
axes.set_xlim([-5,5])
axes.set_ylim([0,1.0])
axes.set_xticks([-5,-4,-3,-2,-1,0,1,2,3,4,5])
axes.set_yticks([0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0])
axes.grid()
plt.plot(x, norm.pdf(x))
plt.plot(x,norm.pdf(x, 1.0, 0.5))

plt.savefig('C:\\Users\\Onyx1\\Pictures\\matplotlib\\matplot_x_y_ticks_bg_grid.jpg', format='jpg')
plt.show()

output:

Saturday, March 28, 2020

how to set xticks and yticks in matplotlib in datascience using python

from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np

axes = plt.axes()
axes.set_xlim([-5,5])
axes.set_ylim([0,1.0])
axes.set_xticks([-5,-4,-3,-2,-1,0,1,2,3,4,5])
axes.set_yticks([0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0])
plt.plot(x, norm.pdf(x))
plt.plot(x,norm.pdf(x, 1.0, 0.5))
plt.show()


output:

matplot lib basics for datascience using python

from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np


x=np.arange(-3,3,0.001)
plt.plot(x,norm.pdf(x))
plt.show()

output:


Multiple plots in one diagram:

plt.plot(x,norm.pdf(x))
plt.plot(x,norm.pdf(x,1.0,0.5))
plt.show()


save the plot in file


output:


how to  save the plots in folders:

plt.plot(x,norm.pdf(x))

plt.plot(x,norm.pdf(x,1.0,0.5))

plt.savefig('C:\\Users\\Onyx1\\Pictures\\matplotlib\\matplot_two_plot.jpg', format='jpg')


percentiles and moments in datascience using python

import numpy as np
import matplotlib.pyplot as plt

vals=np.random.normal(0,0.5,10000)

plt.hist(vals,50)
plt.show()

output:


np.percentile(vals,50)
-0.0006091649949392949
np.percentile(vals,90)
0.6333622008770741

Movements:
import numpy as np
import matplotlib.pyplot as plt

vals=np.random.normal(0,0.5,10000)

plt.hist(vals,50)
plt.show()

output:
np.mean(vals)
0.002411873839262703

np.var(vals)
0.25225058001660977

import scipy.stats as sp
sp.skew(vals)
0.016161251790655015

sp.kurtosis(vals)
-0.034877789070170806


Friday, March 27, 2020

poisson probability mass function in datascience using python

from scipy.stats import poisson
import matplotlib.pyplot as plt
import numpy as np

mu =500
x=np.arange(400,600,0.5)
plt.plot(x,poisson.pmf(x,mu))

output:

threading example in python

from threading import *
import time
e=Event()
def consumer():
    print("consumer thread is waiting for updation")

    e.wait()
    print("consumer got notification and consuming items")

def producer():
    time.sleep(5)
    print("producer thread is producing items")
    print("producer thread giving notification by setting  event")
    e.set()
   
t1=Thread(target=producer)
t2=Thread(target=consumer)
t1.start()
t2.start()

output:
consumer thread is waiting for updation
producer thread is producing items
producer thread giving notification by setting  event
consumer got notification and consuming items

number guess game using python

'''
 You decide you want to play a game where you are hiding
 a number from someone.  Store this number in a variable
 called 'answer'.  Another user provides a number called
 'guess'.  By comparing guess to answer, you inform the user
 if their guess is too high or too low.

 Fill in the conditionals below to inform the user about how
 their guess compares to the answer.
'''
answer = int(input("enter a number as ans"))#provide answer
guess =int(input("enter a number as guess")) #provide guess

if answer > guess :
    #provide conditional
    result = "Oops!  Your guess was too low."
elif answer < guess : #provide conditional
    result = "Oops!  Your guess was too high."
elif answer == guess : #provide conditional
    result = "Nice!  Your guess matched the answer!"

print(result)

output:
enter a number as ans56

enter a number as guess47
Oops!  Your guess was too low.

if elif else in python

"""

Points Prize
1 - 50 wooden rabbit
51 - 150 no prize
151 - 180 wafer-thin mint
181 - 200 penguin
"""

num=int(input("enter a number"))
if num > 1 and num <=50 :
    print("Congratulations! You won a wooden rabbit!")
elif num > 50 and num <=150:
    print("Oh dear, no prize this time.")
elif num > 150 and num <=180:
    print("Congratulations! You won a wafer-thin mint!")
elif num > 180 and num <=200:
    print("Congratulations! You won a penguin")
else :
     print("Oh dear, no prize this time.")

output:
enter a number173
Congratulations! You won a wafer-thin mint!

dictionary in python


elements = {'hydrogen': {'number': 1, 'weight': 1.00794, 'symbol': 'H'},
            'helium': {'number': 2, 'weight': 4.002602, 'symbol': 'He'}}

print(elements)
print("\n hydrogen:",elements['hydrogen'])
print("\n hydrogen_no:",elements['hydrogen']['number'])
print("\n hydrogen_weight:",elements['hydrogen']['weight'])
print("\n hydrogen_symbols:",elements['hydrogen']['symbol'])

print("\n helium:",elements['helium'])

output:
{'hydrogen': {'number': 1, 'weight': 1.00794, 'symbol': 'H'}, 'helium': {'number': 2, 'weight': 4.002602, 'symbol': 'He'}}

 hydrogen: {'number': 1, 'weight': 1.00794, 'symbol': 'H'}

 hydrogen_no: 1

 hydrogen_weight: 1.00794

 hydrogen_symbols: H

 helium: {'number': 2, 'weight': 4.002602, 'symbol': 'He'}


example 2:
cast = {
           "Jerry Seinfeld": "Jerry Seinfeld",
           "Julia Louis-Dreyfus": "Elaine Benes",
           "Jason Alexander": "George Costanza",
           "Michael Richards": "Cosmo Kramer"
       }
for key in cast:
    print(key)

output:
Jerry Seinfeld
Julia Louis-Dreyfus
Jason Alexander
Michael Richards

Bio nomial probability in datascience using python

from scipy.stats import binom
import matplotlib.pyplot as plt
import numpy as np

n,p=10,0.5

x=np.arange(0,10,0.001)
plt.plot(x,binom.pmf(x,n,p))

output:



exponential pdf/ power Law in datascience using python

from scipy.stats import expon
import matplotlib.pyplot as plt
import numpy as np

x=np.arange(0,10,0.001)
plt.plot(x,expon.pdf(x))

output:

Thursday, March 26, 2020

Normal/Gaussian in datascience in python

from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np

x=np.arange(-3,3,0.001)
plt.plot(x,norm.pdf(x))

output:


import matplotlib.pyplot as plt
import numpy as np

mu= 5.0
sigma = 2.0

values = np.random.normal(mu,sigma,10000)
#10000 is data points
plt.hist(values,50)
#50 is number of bars

plt.show()

output:

uniform distribution in datascience uisng python

import numpy as np
import matplotlib.pyplot as plt

values=np.random.uniform(-10.0,10.0,10000)

plt.hist(values,50)
plt.show()

output:

standard deviation in datascience using python matplot lib

import numpy as np
import matplotlib.pyplot as plt

income= np.random.normal(100.0,20.0,10000)

plt.hist(income,50)
plt.show()

output:

income.std()
19.99095786583713

import numpy as np 
import matplotlib.pyplot as plt

income= np.random.normal(100.0,30.0,10000)

plt.hist(income,50)
plt.show()


Mean ,Median and Mode in datascience using python programming

Example1:
import numpy as np
income= np.random.normal(27000,15000,10000)
np.mean(income)

output:
26908.89269950194

%matplotlib inline
import matplotlib.pyplot as plt
plt.hist(income,50)
plt.show()




np.median(income)

output:
26735.667830776893

Mode:
ages=np.random.randint(18,high=90,size=500)
ages
output:
array([62, 66, 21, 39, 74, 56, 20, 35, 29, 37, 53, 88, 39, 54, 45, 34, 22,
       29, 46, 82, 38, 29, 36, 56, 87, 35, 39, 42, 67, 50, 60, 58, 64, 19,
       80, 18, 22, 84, 56, 65, 60, 38, 77, 21, 45, 88, 45, 49, 71, 72, 31,
       77, 41, 41, 27, 50, 51, 81, 29, 22, 41, 71, 78, 69, 41, 35, 43, 21,
       81, 80, 31, 73, 46, 44, 61, 78, 39, 72, 50, 28, 60, 19, 66, 73, 40,
       77, 42, 43, 80, 81, 86, 87, 37, 61, 53, 28, 74, 55, 53, 35, 35, 29,
       49, 82, 75, 19, 57, 53, 19, 55, 34, 45, 80, 62, 43, 56, 86, 69, 33,
       70, 52, 49, 32, 77, 73, 18, 50, 51, 73, 34, 50, 89, 48, 28, 35, 64,
       64, 35, 69, 53, 62, 63, 38, 80, 51, 67, 53, 72, 68, 50, 36, 80, 19,
       74, 39, 59, 53, 83, 82, 70, 63, 78, 25, 59, 22, 47, 39, 36, 60, 35,
       47, 87, 69, 54, 28, 51, 80, 43, 68, 61, 79, 61, 63, 36, 82, 42, 88,
       66, 71, 73, 27, 50, 68, 20, 74, 50, 55, 86, 87, 72, 76, 79, 76, 43,
       74, 19, 27, 60, 40, 61, 82, 26, 52, 62, 32, 20, 20, 25, 20, 84, 83,
       54, 56, 74, 68, 83, 68, 38, 86, 25, 26, 81, 58, 57, 68, 58, 20, 71,
       28, 51, 22, 63, 51, 19, 89, 89, 37, 46, 27, 77, 78, 83, 70, 38, 39,
       67, 18, 52, 85, 37, 31, 27, 85, 81, 86, 59, 49, 22, 26, 44, 32, 58,
       63, 21, 60, 35, 70, 39, 54, 52, 33, 18, 67, 44, 74, 31, 22, 60, 78,
       27, 68, 40, 59, 53, 20, 21, 26, 32, 86, 82, 54, 61, 64, 27, 64, 26,
       51, 55, 70, 30, 18, 40, 31, 44, 40, 64, 73, 89, 75, 39, 20, 85, 20,
       68, 29, 37, 83, 23, 28, 51, 82, 23, 26, 39, 36, 41, 57, 76, 27, 89,
       23, 42, 25, 44, 44, 41, 64, 32, 24, 27, 68, 52, 39, 19, 76, 40, 87,
       68, 66, 30, 53, 54, 32, 63, 28, 85, 36, 87, 66, 59, 80, 88, 53, 66,
       58, 40, 69, 53, 59, 74, 64, 71, 58, 69, 74, 37, 88, 31, 72, 66, 34,
       49, 80, 71, 75, 41, 40, 89, 49, 63, 86, 78, 34, 68, 21, 65, 61, 73,
       49, 35, 84, 23, 79, 64, 79, 65, 54, 75, 25, 82, 22, 73, 89, 58, 66,
       76, 53, 29, 27, 32, 33, 57, 81, 31, 43, 76, 46, 38, 47, 49, 61, 42,
       49, 28, 50, 54, 49, 22, 81, 81, 85, 55, 51, 20, 42, 52, 68, 47, 62,
       29, 75, 55, 55, 57, 21, 43, 52, 57, 47, 63, 46, 38, 73, 46, 72, 54,
       49, 54, 39, 63, 42, 59, 70, 81, 55, 74, 62, 71, 23, 26, 21, 25, 85,
       50, 38, 78, 68, 24, 38, 50])


Wednesday, March 25, 2020

mean,median,mode in datascience using python

Mean:

avg is called as mean
mean=sum of the numbers/total numbers
example:
numbers=1,2,3,4,5,6
sum of numbers=21
total numbers=6
mean=21/6
mean=3.5

Median:

set of numbers:0,1,2,2,0,0,3,2,0
after sorting:0,0,0,0,1,2,2,2,3

"1" is the median of the given set


Mode:

mode is most common number in the given series or set

given series :0,1,2,0,3,1,2,0,6,0

mode is "0"

most common number is zero in the given series





Tuesday, March 24, 2020

pygame colour filling in python


import pygame, sys
from pygame.locals import *
pygame.init()
displaysurf=pygame.display.set_mode((800,400),0,32)
pygame.display.set_caption('Drawing!')
#setup colour
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
SILVER = (192, 192, 192)
PINK=(255,105,180)

displaysurf.fill(WHITE)
pygame.draw.line(displaysurf, BLUE, [0, 0], [100, 100], 30)
pygame.draw.line(displaysurf, BLUE, [0, 0], [100, 100], 10)

#pygame.draw.line(displaysurf, GREEN, [0, 0], [60, 100], 5)
pygame.draw.line(displaysurf, GREEN, [0, 0], [0, 400], 100)
pygame.draw.line(displaysurf, RED, [100,0], [100, 400], 100)
pygame.draw.line(displaysurf, BLACK, [300,0], [300, 400], 100)
pygame.draw.line(displaysurf, BLUE, [400,0], [400, 400], 100)
pygame.draw.line(displaysurf, GREEN, [500, 0], [500, 400], 100)
pygame.draw.line(displaysurf, PINK, [600,0], [600, 400], 100)
pygame.draw.line(displaysurf, SILVER, [700,0], [700, 400], 100)
pygame.draw.line(displaysurf, BLUE, [800,0], [800, 400], 100)


pixobj=pygame.PixelArray(displaysurf)
pixobj[480][380]=BLACK
pixobj[482][382]=BLACK
pixobj[484][384]=BLACK
pixobj[486][386]=BLACK
pixobj[488][388]=BLACK
del pixobj


while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
           
    pygame.display.update()

output:


Monday, March 23, 2020

first pygame in python

import pygame, sys
from pygame.locals import *
pygame.init()
displaysurf=pygame.display.set_mode((400,300))
pygame.display.set_caption('Hello world!!')
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
           
    pygame.display.update()

output:

even or odd using python language

list_of_numbers=[1,2,3,4,5,6]
for number in list_of_numbers:
    if number%2==0:
        print(number,"is even")
    else :
        print(number,"is odd")

print("end of the code")

output:
1 is odd
2 is even
3 is odd
4 is even
5 is odd
6 is even
end of the code

tuple in python

n=input("enter a comma separated number:")
l=n.split(",")
t=tuple(l)
print("l=",l,"t=",t)
print(type(l),"\n",type(t))

output:
enter a comma separated number:2,3,4,5
l= ['2', '3', '4', '5'] t= ('2', '3', '4', '5')
<class 'list'>
 <class 'tuple'>

dictionary in python

n=int(input("enter a number:"))
d=dict()
for i in range(1,n+1):
    #print("i=",i)
    d[i]=i*i
print(d)


output:

enter a number:5
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}


Thursday, March 12, 2020

if and else in python language


x=50
y=50

if x>=0 and x<= 100 and y>=25 and y<=250 :
    print("player is inside the area.sound the alarm")
else:
    print("player is outside  the area. Do  nothing")

output:
player is inside the area.sound the alarm


example2:
israining=True
issunny=True
if israining and issunny:
    print("sun showers")

output:
sun showers

if in python

first=input("First string:")
second=input("second string")
if first>second:
    tup=(first,second)
else:
        tup=(first,second)
print("%s is greater than %s"%tup)

output:
First string:anil

second stringabhi
anil is greater than abhi

How to display scores using python in pygame related


print("%s scored %d and completed %.2f of the quest"%("anil",15,50))

output:
anil scored 15 and completed 50.00 of the quest


example:
print("%20s scored %20d and completed"%("anil",15))

output:
                anil scored                   15 and completed

example3:
print("%-20s%20d"%("anil",15))
output:
anil                                  15

example 4:
print("%-10s%10s%10s\n%-10s%10d%10d\n%-10s%10d%10d"%('Team','Won','Lost','Leafs',1,1,'sabres',0,2))

output:
Team             Won      Lost
Leafs              1         1
sabres             0         2


example 5:
print("%-10s%10s%10s\n%-10s%10d%10d\n%-10s%10d%10d"%('Team','Won','Lost','india',1,1,'srilanka',0,2))

output:
Team             Won      Lost
india                1         1
srilanka           0         2


example 6:
player='abhi'
print(player)

output:
abhi

example7:
formatter="%-10s%10s%10s\n"
header =formatter%("Team","Won","Lost")
india= formatter%("india",1,1)
srikanth= formatter%("srikanth",0,2)

print("%s%s%s"%(header,india,srikanth))
Team             Won      Lost
india              1         1
srikanth           0         2

example 8:
formatter="%-10s%10s%10s\n"
header =formatter%("Team","Won","Lost")
india= formatter%("india",1,1)
srikanth= formatter%("srikanth",0,2)

#print("%s%s%s"%(header,india,srikanth))
table="%s%s%s"%(header,india,srikanth)
print(table)

output:
Team             Won      Lost
india              1         1
srikanth           0         2




Saturday, March 7, 2020

super in Inheritance in python


class a:
    def __init__(self,gene):
        print(gene,"this is initialisation")
        #print(d)
       
    def fn1(self):
        print("this is This is inside fn1")
        #print(d)


class b(a):
    def __init__(self,a):
        print("this is initialisation of b",a)
    def fn2(self,a):
        print(a,"this is This is inside fn2")
        super(). __init__('anil')
       
   
x=5     
buf=b(x)
buf.fn2(x)
print()
x='durgam'
buf=b(x)
buf.fn2(x)

output:
this is initialisation of b 5
5 this is This is inside fn2
anil this is initialisation

this is initialisation of b durgam
durgam this is This is inside fn2
anil this is initialisation

How to write multiple classes and accessing them using python

class a:
    def __init__(self):
        print("this is initialisation")
    def fn1(self):
        print("this is This is inside fn1")


class b:
    def __init__(self):
        print("this is initialisation of b")
    def fn2(self):
        print("this is This is inside fn2")
   
       
buf=a()
buf.fn1()
c=b()
c.fn2()


output:
this is initialisation
this is This is inside fn1
this is initialisation of b
this is This is inside fn2

how to write classes in python

class a:
    def __init__(self):
        print("this is initialisation")
    def fn1(self):
        print("this is This is inside fn1")
       
b=a()
b.fn1()


output:
this is initialisation
this is This is inside fn1

MM32 microcontroller insert form in tkinter python insert data into mysql


from tkinter import *
import pymysql

def View_table():
    mycursor.execute("SELECT * FROM MM32")
    row = mycursor.fetchone()   
    while row is not None:
        print(row)
        row = mycursor.fetchone()

conn=pymysql.connect(host="localhost",user="root",password="",db="my_python")
mycursor=conn.cursor()

#main code start here
class Application:
    def __init__(self, master):
        self.master = master
        # creating the frames in the master
        self.left = Frame(master, width=1024, height=900, bg='steelblue')
        self.left.pack(side=LEFT)

        #self.right = Frame(master, width=400, height=720, bg='steelblue')
        #self.right.pack(side=RIGHT)
       
        # labels for the window
        self.heading = Label(self.left, text="ONYX COMPONENTS & SYSTEMS", font=('arial 35 bold'), fg='black', bg='steelblue')
        self.heading.place(x=100, y=0)
        # patients name
        #PartNo, ARMVer, MaxSpeed,Flash,RAM,GPIO,AdvTimer,GPTM,WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.PartNo = Label(self.left, text="PartNo", font=('arial 12 bold'), fg='black', bg='steelblue')
        self.PartNo.place(x=0, y=80)

        # ARMVer
        self.ARMVer = Label(self.left, text="ARMVer", font=('arial 12 bold'), fg='black', bg='steelblue')
        self.ARMVer.place(x=520, y=80)

        # MaxSpeed
        self.MaxSpeed = Label(self.left, text="MaxSpeed", font=('arial 12 bold'), fg='black', bg='steelblue')
        self.MaxSpeed.place(x=0, y=120)

        # Flash
        self.Flash = Label(self.left, text="Flash", font=('arial 12 bold'), fg='black', bg='steelblue')
        self.Flash.place(x=520, y=120)
       
        # RAM
        self.RAM = Label(self.left, text="RAM", font=('arial 12 bold'), fg='black', bg='steelblue')
        self.RAM.place(x=0, y=160)

         # AdvTimer
        self.GPIO = Label(self.left, text="GPIO", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.GPIO.place(x=520, y=160)
             
        # AdvTimer
        self.AdvTimer = Label(self.left, text="AdvTimer", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.AdvTimer.place(x=0, y=200)
       
         #GPTM
        self.GPTM = Label(self.left, text="GPTM", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.GPTM.place(x=520, y=200)
       
         #WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.WDG = Label(self.left, text="WDG", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.WDG.place(x=0, y=240)
       
        #RTC
        self.RTC = Label(self.left, text="RTC", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.RTC.place(x=520, y=240)
       
        #UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.UART = Label(self.left, text="UART", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.UART.place(x=0, y=280)
       
         #,I2C
        self.I2C = Label(self.left, text="I2C", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.I2C.place(x=520, y=280)
       
         #SPI
        self.SPI = Label(self.left, text="SPI", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.SPI.place(x=0, y=320)
       
        #PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.USB = Label(self.left, text="USB", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.USB.place(x=520, y=320)
       
         #ADC
        self.ADC = Label(self.left, text="ADC", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.ADC.place(x=0, y=360)
       
        #EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.EEPROM = Label(self.left, text="EEPROM", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.EEPROM.place(x=520, y=360)
       
        #DAC
        self.DAC = Label(self.left, text="DAC", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.DAC.place(x=0, y=400)
       
        #CAN,SDIO,COMP,AES,TRNG
        self.CAN = Label(self.left, text="CAN", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.CAN.place(x=520, y=400)
       
        #SDIO,COMP,AES,TRNG
        self.SDIO = Label(self.left, text="SDIO", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.SDIO.place(x=0, y=440)
       
        #SDIO,COMP,AES,TRNG
        self.COMP = Label(self.left, text="COMP", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.COMP.place(x=0, y=480)
       
        #SDIO,COMP,AES,TRNG
        self.AES = Label(self.left, text="AES", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.AES.place(x=520, y=440)

        #SDIO,COMP,AES,TRNG
        self.TRNG = Label(self.left, text="TRNG", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.TRNG.place(x=0, y=520)
       
        #PACK
        self.PACK = Label(self.left, text="PACK", font=('arial 12 bold'), fg='black',bg='steelblue')
        self.PACK.place(x=520, y=480)
        #"""
        # Entries for all labels============================================================
        #
        ################################################################################
        self.PartNo_ent = Entry(self.left, width=30)#1
        self.PartNo_ent.place(x=250, y=80)

        self.ARMVer_ent = Entry(self.left, width=30)
        self.ARMVer_ent.place(x=640, y=80)
   
        self.MaxSpeed_ent = Entry(self.left, width=30)#3
        self.MaxSpeed_ent.place(x=250, y=120)

        self.Flash_ent = Entry(self.left, width=30)
        self.Flash_ent.place(x=640, y=120)

        self.RAM_ent = Entry(self.left, width=30)#5
        self.RAM_ent.place(x=250, y=160)

        self.GPIO_ent = Entry(self.left, width=30)
        self.GPIO_ent.place(x=640, y=160)
       
        self.AdvTimer_ent = Entry(self.left, width=30)#7
        self.AdvTimer_ent.place(x=250, y=200)
       
        self.GPTM_ent = Entry(self.left, width=30)
        self.GPTM_ent.place(x=640, y=200)
       
        self.WDG_ent = Entry(self.left, width=30)#9
        self.WDG_ent.place(x=250, y=240)
       
        self.RTC_ent = Entry(self.left, width=30)
        self.RTC_ent.place(x=640, y=240)
        #WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.UART_ent = Entry(self.left, width=30)
        self.UART_ent.place(x=250, y=280)
       
        self.I2C_ent = Entry(self.left, width=30)
        self.I2C_ent.place(x=640, y=280)
       
        self.SPI_ent = Entry(self.left, width=30)
        self.SPI_ent.place(x=250, y=320)
       
        self.ADC_ent = Entry(self.left, width=30)
        self.ADC_ent.place(x=640, y=320)
       
        self.EEPROM_ent = Entry(self.left, width=30)
        self.EEPROM_ent.place(x=250, y=360)
        #WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.PACK_ent = Entry(self.left, width=30)
        self.PACK_ent.place(x=640, y=360)
       
        #WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.DAC_ent = Entry(self.left, width=30)
        self.DAC_ent.place(x=250, y=400)
       
        #WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.USB_ent = Entry(self.left, width=30)
        self.USB_ent.place(x=640, y=400)
       
        #WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG
        self.CAN_ent = Entry(self.left, width=30)
        self.CAN_ent.place(x=250, y=440)
       
        #SDIO
        self.SDIO_ent = Entry(self.left, width=30)
        self.SDIO_ent.place(x=640, y=440)
       
        #COMP
        self.COMP_ent = Entry(self.left, width=30)
        self.COMP_ent.place(x=250, y=480)
       
        #AES
        self.AES_ent = Entry(self.left, width=30)
        self.AES_ent.place(x=640, y=480)
       
        #TRNG
        self.TRNG_ent = Entry(self.left, width=30)
        self.TRNG_ent.place(x=250, y=520)
       
        # button to perform a command
        self.submit = Button(self.left, text="SUBMIT", width=20, height=2, bg='steelblue', command=self.insert_data_into_table)
        self.submit.place(x=350, y=600)
       
    def create_table(self):
    #uart,i2c,spi,adc,eeprom,pack,dac,,usb,can,sdio,comp,aes,trng
        mycursor.execute("CREATE TABLE MM32 (id INT AUTO_INCREMENT PRIMARY KEY, PartNo VARCHAR(255),ARMVer VARCHAR(255), MaxSpeed VARCHAR(255),Flash VARCHAR(255),RAM VARCHAR(255),GPIO VARCHAR(255),AdvTimer VARCHAR(255),GPTM VARCHAR(255),WDG VARCHAR(255),RTC VARCHAR(255),UART VARCHAR(255),I2C VARCHAR(255),SPI VARCHAR(255),ADC VARCHAR(255),EEPROM VARCHAR(255),PACK VARCHAR(255),DAC VARCHAR(255),USB VARCHAR(255),CAN VARCHAR(255),SDIO VARCHAR(255),COMP VARCHAR(255),AES VARCHAR(255),TRNG VARCHAR(255) )")
        print("Table created")
   
    def insert_data_into_table(self):
        sql = "INSERT INTO MM32 (PartNo, ARMVer, MaxSpeed,Flash,RAM,GPIO,AdvTimer,GPTM,WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG) VALUES (%s, %s ,%s,%s, %s ,%s,%s,%s, %s ,%s,%s, %s ,%s,%s,%s,%s,%s,%s, %s ,%s,%s, %s ,%s)"
        PartNo=input("enter mm32 part")
        ARMVer=input("enter your arm_version")
        MaxSpeed=input("enter your MaxSpeed")
        Flash=input("enter your Flash")
        RAM=input("enter your RAM")
        GPIO=input("enter your GPIO")
        AdvTimer=input("enter your AdvTimer")
        GPTM=input("enter your GPTM")
        WDG=input("enter your WDG")
        RTC=input("enter your RTC")
        UART=input("enter your UART")
        I2C=input("enter your I2C")
        SPI=input("enter your SPI")
        ADC=input("enter your ADC")
        EEPROM=input("enter your EEPROM")
        PACK=input("enter your PACK")
        DAC=input("enter your DAC")
        USB=input("enter your USB")
        CAN=input("enter your CAN")
        SDIO=input("enter your SDIO")#COMP,AES,TRNG
        COMP=input("enter your COMP")
        AES=input("enter your AES")
        TRNG=input("enter your TRNG")
        val = (PartNo, ARMVer,MaxSpeed,Flash,RAM,GPIO,AdvTimer,GPTM,WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG)
        mycursor.execute(sql, val)
        print(mycursor.rowcount, "record inserted.")
    #mycursor.execute(sql, val1)
   
   
####################################################################################
#### main program start from here
####
####################################################################################


conn.commit()

# creating the object
root = Tk()
b = Application(root)

print("\n1.create a table")
print("\n2.insert into table")
print("\n3.View  table")
x=int(input("enter your choice:::"))
if x==1:
    create_table()
elif x==3:
    View_table()
   
elif x==2:
    insert_data_into_table()
   
else :
    print("please enter above options only")
   
#b.create_table()
b.insert_data_into_table()

# resolution of the window
root.geometry("1200x720+0+0")

# preventing the resize feature
root.resizable(False, False)

# end the loop
root.mainloop()


output:


Thursday, March 5, 2020

MM32 microcontroller specification in tkinter in python


from tkinter import *
import pymysql

def create_table():
    #uart,i2c,spi,adc,eeprom,pack,dac,,usb,can,sdio,comp,aes,trng
    mycursor.execute("CREATE TABLE MM32 (id INT AUTO_INCREMENT PRIMARY KEY, PartNo VARCHAR(255),ARMVer VARCHAR(255), MaxSpeed VARCHAR(255),Flash VARCHAR(255),RAM VARCHAR(255),GPIO VARCHAR(255),AdvTimer VARCHAR(255),GPTM VARCHAR(255),WDG VARCHAR(255),RTC VARCHAR(255),UART VARCHAR(255),I2C VARCHAR(255),SPI VARCHAR(255),ADC VARCHAR(255),EEPROM VARCHAR(255),PACK VARCHAR(255),DAC VARCHAR(255),USB VARCHAR(255),CAN VARCHAR(255),SDIO VARCHAR(255),COMP VARCHAR(255),AES VARCHAR(255),TRNG VARCHAR(255) )")
    print("Table created")

def View_table():
    mycursor.execute("SELECT * FROM MM32")
    row = mycursor.fetchone() 
    while row is not None:
        print(row)
        row = mycursor.fetchone()

conn=pymysql.connect(host="localhost",user="root",password="",db="my_python")
mycursor=conn.cursor()


#main code start here
print("\n1.create a table")
print("\n2.insert into table")
print("\n3.View  table")
x=int(input("enter your choice:::"))
if x==1:
    create_table()
elif x==3:
    View_table()
 
elif x==2:
    sql = "INSERT INTO MM32 (PartNo, ARMVer, MaxSpeed,Flash,RAM,GPIO,AdvTimer,GPTM,WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG) VALUES (%s, %s ,%s,%s, %s ,%s,%s,%s, %s ,%s,%s, %s ,%s,%s,%s,%s,%s,%s, %s ,%s,%s, %s ,%s)"
    PartNo=input("enter mm32 part")
    ARMVer=input("enter your arm_version")
    MaxSpeed=input("enter your MaxSpeed")
    Flash=input("enter your Flash")
    RAM=input("enter your RAM")
    GPIO=input("enter your GPIO")
    AdvTimer=input("enter your AdvTimer")
    GPTM=input("enter your GPTM")
    WDG=input("enter your WDG")
    RTC=input("enter your RTC")
    UART=input("enter your UART")
    I2C=input("enter your I2C")
    SPI=input("enter your SPI")
    ADC=input("enter your ADC")
    EEPROM=input("enter your EEPROM")
    PACK=input("enter your PACK")
    DAC=input("enter your DAC")
    USB=input("enter your USB")
    CAN=input("enter your CAN")
    SDIO=input("enter your SDIO")#COMP,AES,TRNG
    COMP=input("enter your COMP")
    AES=input("enter your AES")
    TRNG=input("enter your TRNG")
    val = (PartNo, ARMVer,MaxSpeed,Flash,RAM,GPIO,AdvTimer,GPTM,WDG,RTC,UART,I2C,SPI,ADC,EEPROM,PACK,DAC,USB,CAN,SDIO,COMP,AES,TRNG)
    mycursor.execute(sql, val)
    print(mycursor.rowcount, "record inserted.")
#mycursor.execute(sql, val1)
else :
    print("please enter above options only")

conn.commit()

output:

1.create a table

2.insert into table

3.View  table

enter your choice:::3
(1, 'MM32F003TW', 'CORTEX-M0', '48Mhz', '16Kbytes', '2Kbytes', '16', '1', '5', '2', '-', '1', '1', '1', '8x12-bit', '-', 'TSSOP20', '-', '-', '-', '-', '-', '-', '-')
(2, 'MM32F003NW', 'CORTEX-M0', '48MHZ', '16kbytes', '2kbytes', '16', '1', '5', '2', '-', '1', '1', '1', '8x12-bit ', '-', 'QFN20', '-', '-', '-', '-', '-', '-', '-')

How to insert data into my sql using python language using menu program


from tkinter import *
import pymysql

def create_table():
    mycursor.execute("CREATE TABLE MM32 (id INT AUTO_INCREMENT PRIMARY KEY, PartNo VARCHAR(255),ARMVer VARCHAR(255), MaxSpeed VARCHAR(255),Flash VARCHAR(255),RAM VARCHAR(255),GPIO VARCHAR(255),AdvTimer VARCHAR(255),GPTM VARCHAR(255),WDG VARCHAR(255),RTC VARCHAR(255) )")
    print("Table created")

def View_table():
    mycursor.execute("SELECT * FROM MM32")
    row = mycursor.fetchone() 
    while row is not None:
        print(row)
        row = mycursor.fetchone()

conn=pymysql.connect(host="localhost",user="root",password="",db="sslabs")
mycursor=conn.cursor()


#main code start here
print("\n1.create a table")
print("\n2.insert into table")
print("\n3.View  table")
x=int(input("enter your choice:::"))
if x==1:
    create_table()
elif x==3:
    View_table()
 
elif x==2:
    sql = "INSERT INTO MM32 (PartNo, ARMVer, MaxSpeed,Flash,RAM,GPIO,AdvTimer,GPTM,WDG,RTC) VALUES (%s, %s ,%s,%s, %s ,%s,%s,%s, %s ,%s)"
    PartNo=input("enter mm32 part")
    ARMVer=input("enter your arm_version")
    MaxSpeed=input("enter your MaxSpeed")
    Flash=input("enter your Flash")
    RAM=input("enter your RAM")
    GPIO=input("enter your GPIO")
    AdvTimer=input("enter your AdvTimer")
    GPTM=input("enter your GPTM")
    WDG=input("enter your WDG")
    RTC=input("enter your RTC")
    val = (PartNo, ARMVer,MaxSpeed,Flash,RAM,GPIO,AdvTimer,GPTM,WDG,RTC)
    mycursor.execute(sql, val)
    print(mycursor.rowcount, "record inserted.")
#mycursor.execute(sql, val1)
else :
    print("please enter above options only")

conn.commit()

window with rectangle circle and line using pygame library in python



# Import a library of functions called 'pygame'
import pygame

# Initialize the game engine
pygame.init()

# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)

PI = 3.141592653

# Set the height and width of the screen
#size = (400, 500)
size = (500, 700)
screen = pygame.display.set_mode(size)

pygame.display.set_caption("Professor Craven's Cool Game")

# Loop until the user clicks the close button.
done = False
clock = pygame.time.Clock()

# Loop as long as done == False
while not done:

    for event in pygame.event.get():  # User did something
        if event.type == pygame.QUIT:  # If user clicked close
            done = True  # Flag that we are done so we exit this loop

    # All drawing code happens after the for loop and but
    # inside the main while not done loop.

    # Clear the screen and set the screen background
    screen.fill(WHITE)

    # Draw on the screen a line from (0,0) to (100,100)
    # 5 pixels wide.
    pygame.draw.line(screen, GREEN, [0, 0], [100, 100], 5)
    pygame.draw.line(screen, GREEN, [0, 0], [100, 100], 10)

    # Draw on the screen several lines from (0,10) to (100,110)
    # 5 pixels wide using a loop
    for y_offset in range(0, 100, 10):
        pygame.draw.line(screen, RED, [0, 10 + y_offset], [100, 110 + y_offset], 5)


    # Draw a rectangle
    pygame.draw.rect(screen, BLACK, [20, 20, 250, 100], 2)

    # Draw an ellipse, using a rectangle as the outside boundaries
    pygame.draw.ellipse(screen, BLACK, [20, 20, 250, 100], 2)

    # Draw an arc as part of an ellipse.
    # Use radians to determine what angle to draw.
    pygame.draw.arc(screen, BLACK, [20, 220, 250, 200], 0, PI / 2, 2)
    pygame.draw.arc(screen, GREEN, [20, 220, 250, 200], PI / 2, PI, 2)
    pygame.draw.arc(screen, BLUE, [20, 220, 250, 200], PI, 3 * PI / 2, 2)
    pygame.draw.arc(screen, RED, [20, 220, 250, 200], 3 * PI / 2, 2 * PI, 2)

    # This draws a triangle using the polygon command
    pygame.draw.polygon(screen, BLACK, [[100, 100], [0, 200], [200, 200]], 5)

    # Select the font to use, size, bold, italics
    font = pygame.font.SysFont('Calibri', 25, True, False)

    # Render the text. "True" means anti-aliased text.
    # Black is the color. This creates an image of the
    # letters, but does not put it on the screen
    text = font.render("ANIL DURGAM", True, BLACK)

    # Put the image of the text on the screen at 250x250
    screen.blit(text, [90, 300])

    # Go ahead and update the screen with what we've drawn.
    # This MUST happen after all the other drawing commands.
    pygame.display.flip()

    # This limits the while loop to a max of 60 times per second.
    # Leave this out and we will use all CPU we can.
    clock.tick(60)

# Be IDLE friendly
pygame.quit()




example 2:


# Import a library of functions called 'pygame'
import pygame

# Initialize the game engine
pygame.init()

# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)

PI = 3.141592653

# Set the height and width of the screen
#size = (400, 500)
size = (500, 700)
screen = pygame.display.set_mode(size)

pygame.display.set_caption("Professor Craven's Cool Game")

# Loop until the user clicks the close button.
done = False
clock = pygame.time.Clock()

# Loop as long as done == False
while not done:

    for event in pygame.event.get():  # User did something
        if event.type == pygame.QUIT:  # If user clicked close
            done = True  # Flag that we are done so we exit this loop

    # All drawing code happens after the for loop and but
    # inside the main while not done loop.

    # Clear the screen and set the screen background
    screen.fill(WHITE)

    # Draw on the screen a line from (0,0) to (100,100)
    # 5 pixels wide.
    pygame.draw.line(screen, GREEN, [0, 0], [100, 100], 5)
    pygame.draw.line(screen, GREEN, [0, 0], [100, 100], 10)

    # Draw on the screen several lines from (0,10) to (100,110)
    # 5 pixels wide using a loop
    for y_offset in range(0, 100, 10):
        pygame.draw.line(screen, RED, [0, 10 + y_offset], [100, 110 + y_offset], 5)


    # Draw a rectangle
    pygame.draw.rect(screen, BLACK, [20, 20, 250, 100], 2)

    # Draw an ellipse, using a rectangle as the outside boundaries
    pygame.draw.ellipse(screen, BLACK, [20, 20, 250, 100], 2)

    # Draw an arc as part of an ellipse.
    # Use radians to determine what angle to draw.
    pygame.draw.arc(screen, BLACK, [20, 220, 250, 200], 0, PI / 2, 2)
    pygame.draw.arc(screen, GREEN, [20, 220, 250, 200], PI / 2, PI, 2)
    pygame.draw.arc(screen, BLUE, [20, 220, 250, 200], PI, 3 * PI / 2, 2)
    pygame.draw.arc(screen, RED, [20, 220, 250, 200], 3 * PI / 2, 2 * PI, 2)
   
    ##
    ##
    pygame.draw.arc(screen, BLACK, [30, 220, 250, 200], 0, PI / 2, 2)
    pygame.draw.arc(screen, GREEN, [30, 220, 250, 200], PI / 2, PI, 2)
    pygame.draw.arc(screen, BLUE, [30, 220, 250, 200], PI, 3 * PI / 2, 2)
    pygame.draw.arc(screen, RED, [30, 220, 250, 200], 3 * PI / 2, 2 * PI, 2)
   
    ##
    ##
    pygame.draw.arc(screen, BLACK, [40, 220, 250, 200], 0, PI / 2, 2)
    pygame.draw.arc(screen, GREEN, [40, 220, 250, 200], PI / 2, PI, 2)
    pygame.draw.arc(screen, BLUE, [40, 220, 250, 200], PI, 3 * PI / 2, 2)
    pygame.draw.arc(screen, RED, [40, 220, 250, 200], 3 * PI / 2, 2 * PI, 2)
   
    ##
    ##
    pygame.draw.arc(screen, BLACK, [50, 220, 250, 200], 0, PI / 2, 2)
    pygame.draw.arc(screen, GREEN, [50, 220, 250, 200], PI / 2, PI, 2)
    pygame.draw.arc(screen, BLUE, [50, 220, 250, 200], PI, 3 * PI / 2, 2)
    pygame.draw.arc(screen, RED, [50, 220, 250, 200], 3 * PI / 2, 2 * PI, 2)

    # This draws a triangle using the polygon command
    pygame.draw.polygon(screen, BLACK, [[100, 100], [0, 200], [200, 200]], 5)
     # This draws a triangle using the polygon command
    pygame.draw.polygon(screen, BLUE, [[100, 150], [0, 200], [200, 200]], 5)
    #pygame.draw.circle()
    # Select the font to use, size, bold, italics
    font = pygame.font.SysFont('Calibri', 25, True, False)

    # Render the text. "True" means anti-aliased text.
    # Black is the color. This creates an image of the
    # letters, but does not put it on the screen
    text = font.render("ANIL DURGAM", True, BLACK)

    # Put the image of the text on the screen at 250x250
    screen.blit(text, [90, 300])

    # Go ahead and update the screen with what we've drawn.
    # This MUST happen after all the other drawing commands.
    pygame.display.flip()

    # This limits the while loop to a max of 60 times per second.
    # Leave this out and we will use all CPU we can.
    clock.tick(60)

# Be IDLE friendly
pygame.quit()

pygame_demo_window in python


import pygame

# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)

pygame.init()

# Set the width and height of the screen [width, height]
size = (700, 500)
screen = pygame.display.set_mode(size)

pygame.display.set_caption("My Game")

# Loop until the user clicks the close button.
done = False

# Used to manage how fast the screen updates
clock = pygame.time.Clock()

# -------- Main Program Loop -----------
while not done:
    # --- Main event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

    # --- Game logic should go here

    # --- Screen-clearing code goes here

    # Here, we clear the screen to white. Don't put other drawing commands
    # above this, or they will be erased with this command.

    # If you want a background image, replace this clear with blit'ing the
    # background image.
    screen.fill(GREEN)

    # --- Drawing code should go here

    # --- Go ahead and update the screen with what we've drawn.
    pygame.display.flip()

    # --- Limit to 60 frames per second
    clock.tick(60)

# Close the window and quit.
pygame.quit()

Wednesday, March 4, 2020

Static files adding in django

in setting.py file add this lines STATICFILES_DIRS = [ OS.path.join(BASE_DIR,'static') ] STATIC_ROOT = os.path.join(BASE_DIR,'assets') create "static" foldername first then give the command in python manage.py collectstatic

Monday, March 2, 2020

Entry widget in tkinter python


from tkinter import *
root = Tk()
root.title("Basic Entry Widget")

ent = Entry(root)
ent.pack()

def show_data():
    print(ent.get())
Button(root,
      text="Show Data",
      command=show_data).pack()

root.mainloop()

output

python class topic video