Thursday, March 5, 2020

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

Saturday, February 29, 2020

Python-Tkinter Basics


Python-Tkinter Basics

  1. Why GUI?
    • In simple words to provide simple Graphical User Interface to end users.
  2. What is Tkinter
    • Tkinter is python interface for tk()
    • Tkinter first release was in 1991
  3. Why Tkinter?
  4. Other packages?

Widgets:

  • button
  • canvas
  • checkbutton
  • combobox
  • entry
  • frame
  • label
  • labelframe
  • listbox
  • menu
  • menubutton
  • message
  • notebook
  • tk_optionMenu
  • panedwindow
  • progressbar
  • radiobutton
  • scale
  • scrollbar
  • separator
  • sizegrip
  • spinbox
  • text
  • treeview

Top-level windows:

  • tk_chooseColorpops : up a dialog box for the user to select a color.
  • tk_chooseDirectory : pops up a dialog box for the user to select a directory.
  • tk_dialog : creates a modal dialog and waits for a response.
  • tk_getOpenFile : pops up a dialog box for the user to select a file to open.
  • tk_getSaveFile : pops up a dialog box for the user to select a file to save.
  • tk_messageBox : pops up a message window and waits for a user response.
  • tk_popup : posts a popup menu.
  • toplevel : creates and manipulates toplevel widgets.

Geometry managers:

  1. place : which positions widgets at absolute locations
  2. grid : which arranges widgets in a grid
  3. pack : which packs widgets into a cavity

Package Installation

  • pip install tkinter

Tuesday, February 25, 2020

format in python print statement output

a=5678.1023
b=54578.1023
print("this is monthly salary:",format(a,'>15,.2f'))
print("this is monthly expenses:",format(a,'>13,.2f'))
print("this is monthly saving:",format(a,'>15,.2f'))
print("this is monthly total:",format(a,'>16,.2f'))

output:


example 2:
a=5678.1023 b=54578.1023 print("this is monthly salary:",format(a,'>15,.2f')) print("this is monthly expenses:",format(a,'>13,.3f')) print("this is monthly saving:",format(a,'>15,.4f')) print("this is monthly total:",format(a,'>16,.5f'))

output:


Print output in python language

s="anil"
a=5

print("This is {}".format(s))
print("this is %s"%s)
print('"anil" is thurum\n',end="")
print('"anil" is Thopu')
print("'anil' is daily labour")
b=print(5*4)
print(b)

output:
This is anil
this is anil
"anil" is thurum
"anil" is Thopu
'anil' is daily labour
20
None

Thursday, February 20, 2020

for loop print in one line in python language

for i in range(0,30,5):
    print("loop",i,end=" ")

output:
loop 0 loop 5 loop 10 loop 15 loop 20 loop 25 

Wednesday, February 19, 2020

For loop pattern printing in python


for i in range(5):
    print("anil")
output:
anil
anil
anil
anil
anil

example:
for i in range(0,5,2):
    print("anil",i)

output:
anil 0
anil 2
anil 4

example:
for i in range(0,10,2):
    print("anil",i)

output:
anil 0
anil 2
anil 4
anil 6
anil 8

example :
for i in range(1,10,2):
    print("anil",i)

output:
anil 1
anil 3
anil 5
anil 7
anil 9

example:
for i in range(0,10,5):
    print("anil",i)

output:
anil 0
anil 5

example:
for i in range(0,30,5):
    print("loop",i)

output:
loop 0
loop 5
loop 10
loop 15
loop 20
loop 25

example:

for x in range(5):
    for y in range(5):
        if y>=x:
            print("*",end = '')
    print()


output:
*****
****
***
**
*

example 2:
for x in range(5):
    for y in range(5):
        if y<=x:
            print("*",end = '')
    print()

output:
*
**
***
****
*****

similar output:

for x in range(0,5):
    for y in range(0,x):
        print("*",end='')
    print("\n",end='')

output:
*
**
***
****

example 3:
n=int(input("Enter number of rows:"))
for i in range (1,n+1):
    print(" "*(n-i),end="")
    print("*"*i)

output:
    *
   **
  ***
 ****
*****


example 4:
n=int(input("Enter number of rows:"))
m = (2 * n) - 2
for i in range(0, n):
    for j in range(0, m):
        print(end=" ")
    m = m - 1
    for j in range(0, i + 1):
        print("* ", end=' ')
    print(" ")

output:
Enter number of rows:6
          * 
         *  * 
        *  *  * 
       *  *  *  * 
      *  *  *  *  * 
     *  *  *  *  *  * 

example 5:
k = 0
rows = int(input("enter number of rows:"))
for i in range(1, rows+1):
    for space in range(1, (rows-i)+1):
        print(end="  ")
    while k != (2*i-1):
        print("* ", end="")
        k = k + 1
    k = 0
    print()

output:

enter number of rows:10
                  *
                * * *
              * * * * *
            * * * * * * *
          * * * * * * * * *
        * * * * * * * * * * *
      * * * * * * * * * * * * *
    * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * 

Monday, February 17, 2020

How to Find the Average of the marks of a student in C language

#include <stdio.h>
#include <stdlib.h>

  main()
  {  int m1,m2,m3,m4,m5,sum;
        float avg;
        printf("Enter Subject 1 Marks : ");
        scanf("%d",&m1);
        printf("Enter Subject 2 Marks : ");
        scanf("%d",&m2);
        printf("Enter Subject 3 Marks : ");
        scanf("%d",&m3);
        printf("Enter Subject 4 Marks : ");
        scanf("%d",&m4);
        printf("Enter Subject 5 Marks : ");
        scanf("%d",&m5);
        sum = m1+m2+m3+m4+m5;
        avg = sum/5;
        printf("THE AVERAGE IS  %f",avg);
       }

output:
Enter Subject 1 Marks : 95
Enter Subject 2 Marks : 98
Enter Subject 3 Marks : 93
Enter Subject 4 Marks : 96
Enter Subject 5 Marks : 92
THE AVERAGE IS  94.000000

Sunday, February 16, 2020

Form in tkinter using python

# -*- coding: utf-8 -*-
"""
Created on Mon Feb 17 11:46:43 2020

@author: Onyx1
program:making form using python

"""



import tkinter as tk

def show_entry_fields():
    print("CONTROLLER: %s\nPROCESSOR: %s\nFREQUENCY: %s\nFLASH: %s\nRAM: %s\nGPIO: %s\nADV_TM: %s\nGPTM: %s\nWDG: %s\nRTC: %s\nUART: %s\nI2C: %s\nSPI: %s\nADC: %s\nEEPROM: %s\nPACK: %s\nDAC: %s\nUSB: %s\nCAN: %s\nSDIO: %s\nCOMP: %s\nAES: %s\nTRNG: %s" % (e1.get(),
                                                                                                                                                                                                                                                               e2.get(),
                                                                                                                                                                                                                                                               e3.get(),
                                                                                                                                                                                                                                                               e4.get(),
                                                                                                                                                                                                                                                               e5.get(),
                                                                                                                                                                                                                                                               e6.get(),
                                                                                                                                                                                                                                                               e7.get(),
                                                                                                                                                                                                                                                               e8.get(),
                                                                                                                                                                                                                                                               e9.get(),
                                                                                                                                                                                                                                                               e10.get(),
                                                                                                                                                                                                                                                               e11.get(),
                                                                                                                                                                                                                                                               e12.get(),
                                                                                                                                                                                                                                                               e13.get(),
                                                                                                                                                                                                                                                               e14.get(),
                                                                                                                                                                                                                                                               e15.get(),
                                                                                                                                                                                                                                                               e16.get(),
                                                                                                                                                                                                                                                               e17.get(),
                                                                                                                                                                                                                                                               e18.get(),
                                                                                                                                                                                                                                                               e19.get(),
                                                                                                                                                                                                                                                               e20.get(),
                                                                                                                                                                                                                                                               e21.get(),
                                                                                                                                                                                                                                                               e22.get(),
                                                                                                                                                                                                                                                               e23.get()))

master = tk.Tk()
tk.Label(master, text="CONTROLLER").grid(row=0)
tk.Label(master, text="PROCESSOR").grid(row=1)
tk.Label(master, text="FREQUENCY").grid(row=2)
tk.Label(master, text="FLASH").grid(row=3)
tk.Label(master, text="RAM").grid(row=4)
tk.Label(master, text="GPIO").grid(row=5)
tk.Label(master, text="ADV_TM").grid(row=6)
tk.Label(master, text="GPTM").grid(row=7)
tk.Label(master, text="WDG").grid(row=8)
tk.Label(master, text="RTC").grid(row=9)
tk.Label(master, text="UART").grid(row=10)
tk.Label(master, text="I2C").grid(row=11)
tk.Label(master, text="SPI").grid(row=12)
tk.Label(master, text="ADC").grid(row=13)
tk.Label(master, text="EEPROM").grid(row=14)
tk.Label(master, text="PACK").grid(row=15)
tk.Label(master, text="DAC").grid(row=16)
tk.Label(master, text="USB").grid(row=17)
tk.Label(master, text="CAN").grid(row=18)
tk.Label(master, text="SDIO").grid(row=19)
tk.Label(master, text="COMP").grid(row=20)
tk.Label(master, text="AES").grid(row=21)
tk.Label(master, text="TRNG").grid(row=22)


e1 = tk.Entry(master)
e2 = tk.Entry(master)
e3 = tk.Entry(master)
e4 = tk.Entry(master)
e5 = tk.Entry(master)
e6 = tk.Entry(master)
e7 = tk.Entry(master)
e8 = tk.Entry(master)
e9 = tk.Entry(master)
e10 = tk.Entry(master)
e11 = tk.Entry(master)
e12 = tk.Entry(master)
e13 = tk.Entry(master)
e14 = tk.Entry(master)
e15 = tk.Entry(master)
e16= tk.Entry(master)
e17= tk.Entry(master)
e18= tk.Entry(master)
e19= tk.Entry(master)
e20= tk.Entry(master)
e21= tk.Entry(master)
e22= tk.Entry(master)
e23= tk.Entry(master)

e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
e3.grid(row=2, column=1)
e4.grid(row=3, column=1)
e5.grid(row=4, column=1)
e6.grid(row=5, column=1)
e7.grid(row=6, column=1)
e8.grid(row=7, column=1)
e9.grid(row=8, column=1)
e10.grid(row=9, column=1)
e11.grid(row=10, column=1)
e12.grid(row=11, column=1)
e13.grid(row=12, column=1)
e14.grid(row=13, column=1)
e15.grid(row=14, column=1)
e16.grid(row=15, column=1)
e17.grid(row=16, column=1)
e18.grid(row=17, column=1)
e19.grid(row=18, column=1)
e20.grid(row=19, column=1)
e21.grid(row=20, column=1)
e22.grid(row=21, column=1)
e23.grid(row=22, column=1)

tk.Button(master, text='Quit', command=master.quit).grid(row=23,column=0,sticky=tk.W,pady=4)
tk.Button(master, text='Show', command=show_entry_fields).grid(row=23, column=1, sticky=tk.W,pady=4)

tk.mainloop()

output:




example 2:



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


def show_db():
     mycursor.execute("SELECT * FROM mm32_microcontroller")
     row = mycursor.fetchone()
     while row is not None:
         print(row)
         row = mycursor.fetchone()
   
def insert_db():
    mycursor.execute("INSERT INTO mm32_microcontroller(id,controller,processor,frequency,flash,ram,gpio,adv_tm,gptm,wdg,rtc,uart,i2c,spi,adc,eeprom,pack,dac,usb,can,sdio,comp,aes,trng) VALUES(null,'MM32F003','ARM Cortex M0','48Mhz','16','2','16','1','5','2','-','1','1','1','8x12bit','-','QFN20','-','-','-','-','-','-','-');")
    print("->data inserted")
    conn.commit()
   

def entry_fields():
    tk.Label(master, text="CONTROLLER").grid(row=0)
    tk.Label(master, text="PROCESSOR").grid(row=1)
    tk.Label(master, text="FREQUENCY").grid(row=2)
    tk.Label(master, text="FLASH").grid(row=3)
    tk.Label(master, text="RAM").grid(row=4)
    tk.Label(master, text="GPIO").grid(row=5)
    tk.Label(master, text="ADV_TM").grid(row=6)
    tk.Label(master, text="GPTM").grid(row=7)
    tk.Label(master, text="WDG").grid(row=8)
    tk.Label(master, text="RTC").grid(row=9)
    tk.Label(master, text="UART").grid(row=10)
    tk.Label(master, text="I2C").grid(row=11)
    tk.Label(master, text="SPI").grid(row=12)
    tk.Label(master, text="ADC").grid(row=13)
    tk.Label(master, text="EEPROM").grid(row=14)
    tk.Label(master, text="PACK").grid(row=15)
    tk.Label(master, text="DAC").grid(row=16)
    tk.Label(master, text="USB").grid(row=17)
    tk.Label(master, text="CAN").grid(row=18)
    tk.Label(master, text="SDIO").grid(row=19)
    tk.Label(master, text="COMP").grid(row=20)
    tk.Label(master, text="AES").grid(row=21)
    tk.Label(master, text="TRNG").grid(row=22)

def show_entry_fields():
    print("CONTROLLER: %s\nPROCESSOR: %s\nFREQUENCY: %s\nFLASH: %s\nRAM: %s\nGPIO: %s\nADV_TM: %s\nGPTM: %s\nWDG: %s\nRTC: %s\nUART: %s\nI2C: %s\nSPI: %s\nADC: %s\nEEPROM: %s\nPACK: %s\nDAC: %s\nUSB: %s\nCAN: %s\nSDIO: %s\nCOMP: %s\nAES: %s\nTRNG: %s" % (e1.get(),
                                                                                                                                                                                                                                                               e2.get(),
                                                                                                                                                                                                                                                               e3.get(),
                                                                                                                                                                                                                                                               e4.get(),
                                                                                                                                                                                                                                                               e5.get(),
                                                                                                                                                                                                                                                               e6.get(),
                                                                                                                                                                                                                                                               e7.get(),
                                                                                                                                                                                                                                                               e8.get(),
                                                                                                                                                                                                                                                               e9.get(),
                                                                                                                                                                                                                                                               e10.get(),
                                                                                                                                                                                                                                                               e11.get(),
                                                                                                                                                                                                                                                               e12.get(),
                                                                                                                                                                                                                                                               e13.get(),
                                                                                                                                                                                                                                                               e14.get(),
                                                                                                                                                                                                                                                               e15.get(),
                                                                                                                                                                                                                                                               e16.get(),
                                                                                                                                                                                                                                                               e17.get(),
                                                                                                                                                                                                                                                               e18.get(),
                                                                                                                                                                                                                                                               e19.get(),
                                                                                                                                                                                                                                                               e20.get(),
                                                                                                                                                                                                                                                               e21.get(),
                                                                                                                                                                                                                                                               e22.get(),
                                                                                                                                                                                                                                                               e23.get()))
    controller_value=e1.get()#received value is stored here
    print(controller_value)#checking whether the value is correct or not

master = tk.Tk()
entry_fields()



e1 = tk.Entry(master)

e2 = tk.Entry(master)
e3 = tk.Entry(master)
e4 = tk.Entry(master)
e5 = tk.Entry(master)
e6 = tk.Entry(master)
e7 = tk.Entry(master)
e8 = tk.Entry(master)
e9 = tk.Entry(master)
e10 = tk.Entry(master)
e11 = tk.Entry(master)
e12 = tk.Entry(master)
e13 = tk.Entry(master)
e14 = tk.Entry(master)
e15 = tk.Entry(master)
e16= tk.Entry(master)
e17= tk.Entry(master)
e18= tk.Entry(master)
e19= tk.Entry(master)
e20= tk.Entry(master)
e21= tk.Entry(master)
e22= tk.Entry(master)
e23= tk.Entry(master)

e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
e3.grid(row=2, column=1)
e4.grid(row=3, column=1)
e5.grid(row=4, column=1)
e6.grid(row=5, column=1)
e7.grid(row=6, column=1)
e8.grid(row=7, column=1)
e9.grid(row=8, column=1)
e10.grid(row=9, column=1)
e11.grid(row=10, column=1)
e12.grid(row=11, column=1)
e13.grid(row=12, column=1)
e14.grid(row=13, column=1)
e15.grid(row=14, column=1)
e16.grid(row=15, column=1)
e17.grid(row=16, column=1)
e18.grid(row=17, column=1)
e19.grid(row=18, column=1)
e20.grid(row=19, column=1)
e21.grid(row=20, column=1)
e22.grid(row=21, column=1)
e23.grid(row=22, column=1)

tk.Button(master, text='Quit', command=master.quit).grid(row=23,column=0,sticky=tk.W,pady=4)
tk.Button(master, text='ADD', command=insert_db).grid(row=23, column=1, sticky=tk.W,pady=4)
tk.Button(master, text='Show', command=show_entry_fields).grid(row=23, column=2, sticky=tk.W,pady=4)

print("\nPlease enter your choice\n")
#print
#while True:
choice=int(input("1.add\n2.show\n3.show all\n"))
if choice==1:
    insert_db()
       
elif choice ==2 :
    show_db()
     
else:
        mycursor.execute("SELECT * FROM mm32_microcontroller")
        rows = mycursor.fetchall()
        print('Total Row(s):', mycursor.rowcount)
        for row in rows:
            print(row)

#conn.commit()
conn.close()

tk.mainloop()

output:

Write a program to find area and circumference of a circle In C language

#include <stdio.h>
#include <stdlib.h>

void main()
{ float rad,area,circum;
printf("\n enter radius:    ");
scanf("%f",&rad);
printf("\n radius = %f",rad);
area = 22.0/7.0 * rad * rad;
circum = 2.0 * 22.0/7.0 * rad;
printf("\n area of a circle = %f", area);
printf("\n circumference of a circle = %f", circum);
getch();
}

output:

 enter radius:    10

 radius = 10.000000
 area of a circle = 314.285706
 circumference of a circle = 62.857143

python class topic video