Using Classes/Objects
Part-1
Part-2
This is what I had been asked by my teacher. we have to use python programming to complete these steps but I don't understand how to do this
Part 1 :
# Import only those methods
# which are mentioned below, this way of
# importing methods is efficient
import tkinter as tk import random root = tk.Tk() # width x height + x_offset + y_offset: root.geometry("170x200+30+30") languages = ['Python','Perl','C++','Java','Tcl/Tk'] labels = range(5) for i in range(5): ct = [random.randrange(256) for x in range(3)] brightness = int(round(0.299*ct[0] + 0.587*ct[1] + 0.114*ct[2])) ct_hex = "%02x%02x%02x" % tuple(ct) bg_colour = '#' + "".join(ct_hex) l = tk.Label(root, text=languages[i], fg='White' if brightness < 120 else 'Black', bg=bg_colour) l.place(x = 20, y = 30 + i*30, width=120, height=25) root.mainloop()
Note: One can also add another LabelFrame inside another LabelFrame, as well as one can do styling of any LabelFrame like we do the styling of other widgets.
Part 2:
SQLite is a self-contained transactional relational database engine that doesn't require a server configuration, as in the case of Oracle, MySQL, etc.
Create a New Table
A string enclosing the CREATE TABLE query is passed as parameter to the execute() method of the cursor object. The following code creates the student table in the test.db database.
Example: Create a New Table in Sqlite
import sqlite3 db=sqlite3.connect('test.db') try: cur =db.cursor() cur.execute('''CREATE TABLE student ( StudentID INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT (20) NOT NULL, age INTEGER, marks REAL);''') print ('table created successfully') except: print ('error in operation') db.rollback() db.close()
Example: Insert a Record in Sqlite
import sqlite3 db=sqlite3.connect('test.db') qry="insert into student (name, age, marks) values('Rajeev', 20, 50);" try: cur=db.cursor() cur.execute(qry) db.commit() print ("one record added successfully") except: print ("error in operation") db.rollback() db.close()
Example: Fetch Records
import sqlite3 db=sqlite3.connect('test.db') sql="SELECT * from student;" cur=db.cursor() cur.execute(sql) while True: record=cur.fetchone() if record==None: break print (record) db.close()
Using Classes/Objects Part-1 Create 3 frame/label objects Place 2 objects side-by-side on top of the screen...
QUESTION 28 Control handles on each corner and each side let you reduce the size of a picture. True False QUESTION 29 In a window, the Address bar is located just above the title bar True False QUESTION 30 Report data can be from one or True multiple database objects False QUESTION 31 Blank workbook is a type of Excel template you can choose. True False QUESTION 32 manage the system resources of a computer so programs can run properly...
You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...
PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...
#include <iostream> #include <iomanip> #include <vector> using namespace std; Part 1. [30 points] In this part, your program loads a vending machine serving cold drinks. You start with many foods, some are drinks. Your code loads a vending machine from foods, or, it uses water as a default drink. Create class Drink, make an array of drinks, load it and display it. Part 1 steps: [5 points] Create a class called Drink that contains information about a single drink. Provide...
If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...