Sunday, November 24, 2019

pygame introduction program

this code shows that how to display a window using pygame library


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(WHITE)

    # --- 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()

Thursday, November 21, 2019

tkinter label example

from tkinter import *
root = Tk()

one =Label(root,text="ONE",bg="red",fg="white")
one.pack()
two =Label(root,text="TWO",bg="green",fg="black")
two.pack(fill=X)
three =Label(root,text="THREE",bg="blue",fg="white")
three.pack(side=LEFT,fill=Y)


root.mainloop()

output:

tkinter example making of button


from tkinter import *

mm32=tk.Tk()

topframe = Frame(mm32)
topframe.pack()
bottomframe=Frame(mm32)
bottomframe.pack(side=BOTTOM)

button1=Button(topframe,text="MM32F",fg="red",font=('Helvetica', 15))
button2=Button(topframe,text="MM32L",fg="red",font=('Helvetica', 15))
button3=Button(topframe,text="MM32SPIN",fg="red",font=('Helvetica', 15))
button4=Button(topframe,text="MM32W",fg="red",font=('Helvetica', 15))
button5=Button(topframe,text="MM32P",fg="red",font=('Helvetica', 15))

button1.pack(side=LEFT)
button2.pack(side=LEFT)
button3.pack(side=LEFT)
button4.pack(side=LEFT)
button5.pack(side=LEFT)

mm32.mainloop()

OUTPUT:


tkinter introduction


from tkinter import *
root = Tk()
root.mainloop()

output:




from tkinter import *

mm32=tk.Tk()

thelabel=tk.Label(text="MM32_DATASHEETS", font=('Helvetica',20), fg='green')
thelabel.pack()
mm32.configure(background="light green")

mm32.mainloop()

output:

Wednesday, November 20, 2019

drop down list using tkinter library in python

try:
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk
def select():
    sf = "value is %s" % var.get()
    root.title(sf)
    # optional
    color = var.get()
    root['bg'] = color
root = tk.Tk()
# use width x height + x_offset + y_offset (no spaces!)
#root.geometry("%dx%d+%d+%d" % (330, 80, 200, 150))
#root.geometry("%dx%d+%d+%d" % (220, 40, 200, 150))
root.title("MM32_MICROCONTROLLER_DATA")
root.configure(background="light green")
var = tk.StringVar(root)
# initial value
var.set('MM32F_SERIES')
choices = ['MM32F_SERIES', 'MM32L_SERIES', 'MM32SPIN_SERIES', 'MM32W_SERIES','MM32P_SERIES']
Fchoices = ['MM32F003', 'MM32L_SERIES', 'MM32SPIN_SERIES', 'MM32W_SERIES','MM32P_SERIES']
option = tk.OptionMenu(root, var, *choices)
option.pack(side='left', padx=1, pady=1)
button = tk.Button(root, text="check value slected", command=select)
button.pack(side='left', padx=20, pady=1)
root.mainloop()

output





matrix list in python

a=[[10,20,30],[25,40,50],[60,70,80]]
print(a)
for r in a:
    print(r)

output:
[[10, 20, 30], [25, 40, 50], [60, 70, 80]]
[10, 20, 30]
[25, 40, 50]
[60, 70, 80]

nested list in python

a=[10,20,[30,40]]
print(a)
print(a[0])
print(a[1])
print(a[2][0])
print(a[2][1])

output:
[10, 20, [30, 40]]
10
20
30
40

clear method in python

clear method is used for to clear entire list ,list elements

a=[10,20,30]
print(a)
a.clear()
print(a)

output:
[10, 20, 30]
[]

list elements check using print

a=[10,20,30]
print(10 in a)
print(100 in a)
print(100 not in a)

output:
True
False
True

comparing the list elements in python


comparing list elements.

x=['abc','bcd','cde']
y=['abc','bcd','cde']
z=['ABC','BCD','CDE']
print(x==y)
print(x==z)
print(x!=z)

output:
True
False
True

example 2:
x=['abc','bcd','cde']
y=['abc','bcd','cde']
z=['ABC','BCD','CDE']
print(x[0] is y[0])
print(x==z)
print(x!=z)

output:
True
False
True

mathematical operation on the list in python

a1=[20,5,16,10,8]
a2=[10, 20, 30, 40]
c=a1+a2
print(c)

output:
[20, 5, 16, 10, 8, 10, 20, 30, 40]

python class topic video