Style and Use Entry Box in tkinter and TextBox in tkinter

If you want to use Entry Box in tkinter and TextBox in tkinter or you can say that tkinter Entry Widget and tkinter Text Widget. So, here we describe following way to use or Style EntryBox or Style TextBox in tkinter. The Text or Entry widget Style will be defined in following points.
 
  1. Create and Set Location and Size of Entry or Text Widget in tkinter
  2. Set Color of Entry or Text in tkinter
  3. Set Selection Background and Foreground Color of Entry or Text in tkinter
  4. Text or Entry Box Font Setting in tkinter
  5. Text or Entry Border Style in tkinter


Tkinter Entry Widget Style in Python

Now, here we learn interesting way to style widget in tkiter.


(1). Create and Set Location and Size of Entry or Text Widget in tkinter :

Now, if you want to set particular control or widget in desire location of window and want to set Entry box Height and Width in tkinter then we use “place” method in following way:

from tkinter import *  

TkFrm = Tk()
TkFrm.geometry("250x200+500+400")
TkFrm.title('Entry Box or Text Box Location And Size in Tkinter')
#Create Entry Box
MyEntryBox1 = Entry(TkFrm)
#Set Entry Widget Location and Size in Form
MyEntryBox1.place(x=14, y=30,  width=256, height= 35)
#Add Text to Entry Widget in Python
MyEntryBox1.insert(END, 'SKOTechLearn')

#Create Entry Box
MyTxtBox = Text(TkFrm)
#Set Text Widget Location and Size in Form
MyTxtBox.place(x=14, y=90, width=256, height=50)
#Add Text to Text Widget in Python
MyTxtBox.insert(END, 'SKOTechLearn')

TkFrm.mainloop()



Here we add some text in both widgets in python tkinter. And after running it will show output:

Tkinter Entry Size and Location


This way we can increase or decrease height and width of tkinter widgets.
 

(2). Set Color of Entry or Text in tkinter :

Here, we set Background, Foreground, Border Selection color or Entry Box or Text Box in Tkinter.

Following method will use for color setting in tkinter:
MethodDetails
bg or background Use for Background color of Widgets
Fg or foreground Use for Font color of widgets
highlightbackground This method is use for Border color
highlightcolor This method is use for border color when focus on entry or text widget.


Entry And Text Widget Color Setting in tkinter:

When you want to apply border color change when lost focus and got focus, and want to change font and back color, you have to apply and write following code:

from tkinter import *  

TkFrm = Tk()
TkFrm.geometry('290x200+500+300')
TkFrm.title('Entry Box or Text Box Color Setting in Tkinter')

#Set Entry Widget Color and Border Color
MyEntryBox1 = Entry(TkFrm, highlightcolor = 'green', bg='#F3FEFF', fg='red', highlightbackground='red')

#Set Widget Location and Size in Tkinter
MyEntryBox1.place(x=14, y=30,  width=256, height= 35)
#Add Text to Entry Widget in Python
MyEntryBox1.insert(END, 'SKOTechLearn')

# Text Widget Color and border Color in Tkinter
MyTxtBox = Text(TkFrm, highlightcolor = 'blue', highlightbackground='brown', fg='Navy', bg='#FFEFE7')
#Set Widget Location and Size in Form
MyTxtBox.place(x=14, y=90, width=256, height=50)
#Add Text to Text Widget in Python
MyTxtBox.insert(END, 'SKOTechLearn')

TkFrm.mainloop()


When you execute this code, and when you focus on widget, it will change the border color as describe bellow image.

Set Tkinter Entry widget Color in Python



(3). Set Selection Background and Selection Foreground Color of Entry or Text in tkinter :

If you want to change Selection Color, when you select String or Value in Entry or Text Box, then you have to use ‘selectbackground’ for selection back color and ‘selectforeground’ for selection font color.

from tkinter import *  

TkFrm = Tk()
TkFrm.geometry('290x200+500+300')
TkFrm.title('Entry Box or Text Box Selection Color in Tkinter')

#Selection Color Setting in Tkinter Entry Widget
MyEntryBox1 = Entry(TkFrm,  selectbackground='yellow', selectforeground='green')
MyEntryBox1.place(x=14, y=30,  width=256, height= 35)
MyEntryBox1.insert(END, 'SKOTechLearn')

#Selection Color Setting in Tkinter Text Widget
MyTxtBox = Text(TkFrm, selectforeground='yellow', selectbackground='red')
MyTxtBox.place(x=14, y=90, width=256, height=50)
MyTxtBox.insert(END, 'SKOTechLearn')

TkFrm.mainloop()


Output:

Tkinter Entry Selection Color in Python



(4). Text or Entry Box Font Setting in tkinter :

Now, lets see the code, how to change font in Entry widget in tkinter or change font in Text widget in tkinter. Or Change the font size in tkinter widgets.

from tkinter import *  

TkFrm = Tk()
TkFrm.geometry('290x200+500+300')
TkFrm.title('Entry Box or Text Box Font Setting in Tkinter')

#Font Settings in tkinter
MyEntryBox1 = Entry(TkFrm,  font='Verdana 12 bold')
MyEntryBox1.pack()
MyEntryBox1.insert(END, 'SKOTechLearn')

#Font Settings in tkinter
MyTxtBox = Text(TkFrm, font='Georgia 13 italic bold')
MyTxtBox.pack()
MyTxtBox.insert(END, 'SKOTechLearn')

TkFrm.mainloop()


Output:

Entry widget Font Setting in Tkinter



(5). Text or Entry Border Style in tkinter :

Now, let’s find the last point to change Border Style in tkinter widgets. Can use following method in you code. You can change style of Text Widget Border in tkinter or Entry Widget Border in Tkinter.

MethodDetails
relief Change Border Style (raised, sunken, solid, flat, ridge, groove)
highlightthickness Change Border width when widget gain focus
borderwidth Change Border Width


Lets find code:

from tkinter import *  

TkFrm = Tk()
TkFrm.geometry('290x200+500+300')
TkFrm.title('Entry Box or Text Box Border Setting in Tkinter')

#Tkinter Widgets Border Setting
MyEntryBox1 = Entry(TkFrm,  relief='raised', highlightthickness=1, borderwidth=2)
MyEntryBox1.pack()
MyEntryBox1.insert(END, 'SKOTechLearn')

#Tkinter Widgets Border Style
MyTxtBox = Text(TkFrm, relief='sunken', highlightthickness=1, borderwidth=2)
MyTxtBox.pack()
MyTxtBox.insert(END, 'SKOTechLearn')

TkFrm.mainloop()


Output:

Tkinter Entry Border Style

So, this way you can change Enty Widget Style in Tkinter or Text Widget Style in Tkinter.

PySide Center Screen and Window State Maximized in PySide

As you know PySide provide stylish GUI comparing Tkinter and feature rich QT base application. So first, here we learn how to set Center Screen window in Pyside in Python? And also we learn Window State Maximize in Pyside in Python. Here we also include how to Set window title in PySide?

Let’s find it in following points:

  1. Set window Size in PySide6 and Set Window Location in PySide6
  2. Python Center Screen Window in PySide6
  3. Set Window State Maximized in PySide6
  4. Set Window Title in PySide6


Window State Maximize in PySide


How to Set Center Screen in Tkinter and Set window size in Tkinter?

(1). Set Window Size in PySide6 and Set Window Location in Pyside6 :

Suppose, you want to create a Form using PySide and want to display at run time with specific size with specific location on screen. Then here PySide provide ‘setGeometry’ or ‘move’ and ‘resize’ function. The syntax is used in following way:


‘setGeometry’ Syntax:
MainForm.setGeometry(Form_Left, Form_Top, Form_Width, Form_Height)

Example:
from PySide6.QtWidgets import QMainWindow, QApplication

SKapp = QApplication()
MyPyForm = QMainWindow()

#Set Form's Location and Size
MyPyForm.setGeometry(150, 100, 330, 250)

MyPyForm.show()

SKapp.exec()




‘move’ Syntax:
MainForm.move(Left_Location, Top_Location)


‘resize’ Syntax:
MainForm.resize(Form_Width, Form_Height)


Now, we are using both function in given example:
from PySide6.QtWidgets import QMainWindow, QApplication

SKapp = QApplication()
MyPyForm = QMainWindow()

#Set Location of Form in PySide
MyPyForm.move(150, 100)
#Set Form Size in PySide
MyPyForm.resize(330, 250)

MyPyForm.show()

SKapp.exec()


Now, you will get same output when run application like bellow:

Set Window Size and Location in Pyside



(2). Python Center Screen Window in PySide6 :

In this point, we learn how to set start position for form in center screen. For center screen form in Pyside we have to import following:
from PySide6.QtGui import QScreen

Here are following two ways from which you can set Center Screen in Python.

Note: Remember one thing before positioning form in center screen, you have to first define the form or dialog size then write center screen code.

First we use ‘QScreen.availableGeometry(QApplication.primaryScreen())’. This will show screen available geometry.

PySide Center Screen Example 1:
from PySide6.QtWidgets import QMainWindow, QApplication
from PySide6.QtGui import QScreen

SKapp = QApplication()
MyPyForm = QMainWindow()

#Set Form Size
MyPyForm.resize(330, 250)

#Get Screen geometry
SrcSize = QScreen.availableGeometry(QApplication.primaryScreen())
#Set X Position Center
frmX = (SrcSize.width() - MyPyForm.width())/2
#Set Y Position Center
frmY = (SrcSize.height() - MyPyForm.height())/2
#Set Form's Center Location
MyPyForm.move(frmX, frmY)

MyPyForm.show()

SKapp.exec()


Pass Value from Text To Label in Tkinter.


Pyside Center Screen Example 2:
from PySide6.QtWidgets import QMainWindow, QApplication
from PySide6.QtGui import QScreen

SKapp = QApplication()
MyPyForm = QMainWindow()

#Set Form's Location and Size
MyPyForm.resize(330, 250)

#Get Screen Center Position
Fmcenter = QScreen.availableGeometry(QApplication.primaryScreen()).center()
Fmscr = MyPyForm.frameGeometry()

#Set Form in Center Position
Fmscr.moveCenter(Fmcenter)

MyPyForm.show()

SKapp.exec()



Both codes will show same output:
Pyside Center Screen Window





(3). Set Window State Maximized in Pyside6 :

Here SKOTechLearn describe two way to set window state maximized in PySide, and both will show same output as described bellow:

PySide6 Maximized Form Example 1:

from PySide6.QtWidgets import QMainWindow, QApplication
from PySide6.QtGui import QScreen

SKapp = QApplication()
MyPyForm = QMainWindow()

#Set Form's Location and Size
MyPyForm.resize(330, 250)

SrcSize = QScreen.availableGeometry(QApplication.primaryScreen())

#Get Screen Width
frmX=SrcSize.width()

#Get Screen Height
frmY=SrcSize.height()

#Pyside Window State maximized
MyPyForm.setGeometry(0, 0, frmX, frmY)

MyPyForm.show()

SKapp.exec()



PySide6 Maximize Form Example 2:

import sys
from PySide6.QtWidgets import QMainWindow, QApplication
from PySide6.QtGui import QScreen

class App(QMainWindow):

    def __init__(self):
        super().__init__()
        self.title = 'PySide6 Maximize Window State'
        
        #Pyside6 Maximize Form
        MyScn = QScreen
        self.setGeometry(0, 0, MyScn.availableGeometry(QApplication.primaryScreen()).width(), MyScn.availableGeometry(QApplication.primaryScreen()).height())  
    
        self.show()    
    
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec())


You will get maximized form:
PySide Maximize Window State




(4). Set Window Title in PySide6 :

The simple way to set window title or form title in PySide using ‘setWindowTitle’. Her we use it with two way at design time and change Form title in PySide at run time.


(i). Set Window Title at design time :
import sys
from PySide6.QtWidgets import QApplication, QMainWindow

app = QApplication(sys.argv)
mainwindow = QMainWindow()

mainwindow.setGeometry(300, 300, 300, 150)

#Set Window Title in PySide
mainwindow.setWindowTitle('PySide Set Window Title')

mainwindow.show()

app.exec()   



(ii). Set Window Title at run time :

Here we use ‘QPushButton’ to change Title at run time when we click on button.
import sys
from PySide6.QtWidgets import QMainWindow, QPushButton, QApplication

class MyTitle(QMainWindow):
    
    def __init__(self):
        super().__init__()
        
        self.initUI()
        
    def initUI(self):      

        Pysbtn = QPushButton('Show title', self)
        Pysbtn.move(70, 40)
        
        #Call Click Event which is defined bellow
        Pysbtn.clicked.connect(self.ClickToChangeTitle)
        
        self.setGeometry(300, 300, 300, 150)
        self.show()


    #QPushButton Click Event in PySide    
    def ClickToChangeTitle(self):
            self.setWindowTitle('Click to Change Title in Pyside')
        
if __name__ == '__main__':  
    app = QApplication(sys.argv)
    ex = MyTitle()
    sys.exit(app.exec())


Output:
Set Window Title in PySide


Set Window Title in Python


Now here are some Pyside windows tips, this way you can easily Maximized Window in PySide and Also Set Center Screen Window in PySide in Python. And Also Set Window Title or Form Title in PySide.

Use ScrollBar in Tkinter and Set ScrollBar in TextBox in Tkinter

If we are creating a project and want to start programming in python using tkinter and want to use scrolling in many widgets like- TextBox, Listbox, TreeView etc. Then we will use ScrollBar widget in Tkinter python.

Here we learn How to use ScrolledText in Tkinter or how can we Set Scrollbar in Textbox in Python Tkinter or How to use Tkinter ScrollBar in Python?
 
So, Lets learn Following Point wise steps.

  1. Learn about Tkinter ScrollBar in Python
  2. Change Tkinter ScrollBar Color and Style
  3. How to Set ScrollBar in Textbox in Python Tkinter


Tkinter ScrollBar in Python


When you are start programming in python, you will find very useful widget, as you know Scrollbar Widget in tkinter, you can use it in many widgets.


(1). Learn About Tkinter ScrollBar in Python :

In Python you can find that, you can use scrollbar in vertical and horizontal way.


Vertical ScrollBar in Tkinter:
 This will scroll the details or information of a widget from up to down. You can scroll down or return to scroll up for getting information given inside a widget.
Vertical ScrollBar in Python



Horizontal ScrollBar in Tkinter:
  This will scroll the details of information of a widget from left to right. You can scroll left or return to right to get information given inside that particular widget.

Horizontal ScrollBar in Tkinter



(2). Change Tkinter ScrollBar Color and Style :

For styling scrollbar, we use “ttk.Style ()”. Using Style will change the Background, DarkColor, LightColor, ArrowColor, TroughColor etc. Example is given bellow:


Note: For using style, you have to use ttk.Scrollbar in your application.


Syntax:
style = ttk.Style()
#Set Style
style.configure('SetStyleName', background='Set Color', troughcolor='Set Color', arrowcolor='Set Color', highlightcolor='Set Color') 

Vsrl.configure(style = 'SetStyleName')


Example:

from tkinter import *
from tkinter import ttk

SKForm = Tk()
SKForm.title('Tkinter Scroll TextBox')

Vsrl = ttk.Scrollbar(SKForm)
Vsrl.pack(side = RIGHT, fill = Y)

#Create Style For ScrollBar
style = ttk.Style()
#Set Style For ScrollBar
style.configure('TScrollbar', background='#E66565', troughcolor='#E0F5DA', arrowcolor='#65E6A9', highlightcolor='#E0F5DA') 

Vsrl.configure(style = 'TScrollbar')

MyTkTextBox = Text(SKForm, yscrollcommand = Vsrl.set)

MyTkTextBox.config(wrap = NONE, width = 22, height = 12)

#Add Record in TextBox in Tkinter
for ist in range(16):
    MyTkTextBox.insert(END, str(ist) + " = Set Horizontal and Vertical Scroll Bar in TextBox"+ "\n")

MyTkTextBox.pack(side = TOP, fill = "both", expand = True)

Vsrl.config(command = MyTkTextBox.yview)

SKForm.mainloop()


Add Text in TextBox in Tkinter


Output:


Tkinter ScrollBar Style in Python


(3). How to Set ScrollBar in Textbox in Python Tkinter :

If you want to set Scroll Bar in Text in Tkinter. Here we will write some sentences or multi-line text in TextBox in Tkinter. And want to scroll then we use following code for scrolling.
 
Set Vertical ScrollBar in TextBox in Tkinter:

from tkinter import *

SKForm = Tk()
SKForm.title('Vertical Scroll TextBox')

Vsrl = Scrollbar(SKForm)
Vsrl.pack(side = RIGHT, fill = Y)

MyTkTextBox = Text(SKForm,  yscrollcommand = Vsrl.set)
MyTkTextBox.config(wrap = NONE, width = 22, height = 12)

for ist in range(16):
    MyTkTextBox.insert(END, str(ist) +" = Set Vertical Scroll Bar in TextBox"+ "\n")

MyTkTextBox.pack(side=TOP, fill="both", expand=True)

# Set Vertical Scroll Bar to configure Text Y View
Vsrl.config(command = MyTkTextBox.yview)

SKForm.mainloop()


Now, you will get the given output.

 
Set Vertical Scroll Bar in TextBox Tkinter



Using ScrolledText in Tkinter for Vertical Scrolling:

When you will use ScrolledText Widget in Tkinter, there is no need for add extra Scroll widget in Tkinter for Vertical Scrolling. ScrolledText Widget has inbuilt Vertical Scrollbar as describe in bellow python code:
from tkinter import *
from tkinter.scrolledtext import ScrolledText

SKForm = Tk()
SKForm.title('ScrolledText in Tkinter')

skt = ScrolledText(SKForm)
skt.config(width = 39, height = 6)

#Add Text in ScrolledText in Tkinter
for ist in range(8):
    skt.insert(END, str(ist) +" = Using ScrolledText Widget Scroll "+ "\n")
    
skt.pack()

SKForm.mainloop()


Now, let’s see the output:

ScrolledText in Tkinter



(c) Set Vertical and Horizontal ScrollBar in TextBox in Tkinter:

Here we use Both Vertical and Horizontal ScrollBar in Text widget in Tkinter. Or here we set ScrollBar Orientation in Tkinter.
 

Horizontal ScrollBar in Text in Tkinter


Example:

from tkinter import *

SKForm = Tk()
SKForm.title('Tkinter Scroll TextBox')

#Create Horizontal ScrollBar in Tkinter
Hsrl = Scrollbar(SKForm, orient = 'horizontal')
Hsrl.pack(side = BOTTOM, fill = X)

#Create Vertical ScrollBar in Tkinter
Vsrl = Scrollbar(SKForm)
Vsrl.pack(side = RIGHT, fill = Y)

#Create TextBox and Set Scroll Bar
MyTkTextBox = Text(SKForm, xscrollcommand = Hsrl.set, yscrollcommand = Vsrl.set)

MyTkTextBox.config(wrap = NONE, width = 22, height = 12)

for ist in range(16):
    MyTkTextBox.insert(END, str(ist) +" = Set Horizontal and Vertical Scroll Bar in TextBox"+ "\n")

#Set TextBox widget to Form at top
MyTkTextBox.pack(side=TOP, fill="both", expand=True)

# Set Horizontal Scroll Bar to configure Textox X View
Hsrl.config(command = MyTkTextBox.xview)

# Set Vertical Scroll Bar to configure Textox Y View
Vsrl.config(command = MyTkTextBox.yview)

SKForm.mainloop()


Output:

Horizontal and Vertical Scrollbar in Tkinter

After running application, this will show above given output, you can easily scroll your Textbox content left to right or Up and down.

So, this way SKOTechLearn describe the way to use ScrollBar in Tkinter Python or you can set ScrollBar in Text Widget in Tkinter.


How to Connect or Show Data from SQLite in VB.Net or C#

As you know that SQLite free to use in any platform. But here we will learn How to Use SQlite Database in VB.net and we will also learn how to show SQLite Data in VB.Net or C#

But In Vb.net if we want to call data from SQLite then we have to use “System.Data.SQLite.dll” file or add as reference in VB.Net. Now when we insert this dll file, we have first import following class in your programming.

SQLIte Connect With VB.Net

VB.Net :

Imports System.Data.SQLite

C# :
using System.Data.SQLite;

After that we will proceed with following points:

  1. How to Connect SQLite in VB.Net
  2. Show Data from SQLite in VB.Net through Query
  3. Show SQlite Data in ListBox in VB.Net
  4. Show SQLite Data in Listview in VB.Net

When you add this reference to your vb project then you have to first learn what is the SQLite ConnectionString in VB.Net

First, there is following table we created in Sqlite3 Database.

Create Table in SQLite Database
SQLite Database with Tables


After that we will learn point wise described bellow.


(1). How to Connect SQLite in VB.Net :

For any database connection in any programming language require ConnectionString, so first we will write code for connection String:

VB:
Dim SQLiteConn As New SQLiteConnection

SQLiteConn.ConnectionString = "Data Source=MyPath\MysqliteFile.db; Integrated Security=true"

SQLiteConn.Open()



C#:
SQLiteConnection SQLiteConn = new SQLiteConnection();

SQLiteConn.ConnectionString = @"Data Source=MyPath\MysqliteFile.db; Integrated Security=true";

SQLiteConn.Open();


This way you can connect SQLite with VB.Net.


(2). Show Data from SQLite in VB.Net through Query :

Now, Lets try to show data from Local SQLite Database’s Tables through query in VB.Net. Suppose we want to show only single record of one field then we have to write following code:

VB:
Dim SQLitecnStr As String ="Data Source=C:\MYSQLiteDBForVB.db; Integrated Security=true"
Dim SQLiteConn As New SQLiteConnection
Dim SQLitecmd As New SQLiteCommand
Dim SQLiteReader As SQLiteDataReader

SQLiteConn.ConnectionString = SQLitecnStr
SQLiteConn.Open()

SQLitecmd.Connection = SQLiteConn
SQLitecmd.CommandText = "SELECT * from MySQLiteTable LIMIT 1;"
SQLiteReader = SQLitecmd.ExecuteReader()
	
Msgbox(SQLiteReader("MyName").ToString)

SQLiteReader.Close()
SQLiteConn.Close()


C#:
string SQLitecnStr = @"Data Source=C:\MYSQLiteDBForVB.db; Integrated Security=true";
SQLiteConnection SQLiteConn = new SQLiteConnection();
SQLiteCommand SQLitecmd = new SQLiteCommand();
SQLiteDataReader SQLiteReader;
	
SQLiteConn.ConnectionString = SQLitecnStr;
SQLiteConn.Open();
	
SQLitecmd.Connection = SQLiteConn;
SQLitecmd.CommandText = "SELECT * from MySQLiteTable LIMIT 1;";
SQLiteReader = SQLitecmd.ExecuteReader();
	
MessageBox.Show(SQLiteReader["MyName"].ToString(), "SQLite Connection in VB.Net");
	          
SQLiteReader.Close();
SQLiteConn.Close();


When we execute this code, the output will present in MessageBox.

Show MessageBox in VB.Net


(3). Show SQLite Data in ListBox in VB.Net :

Now, Suppose you want to show SQlite’s Table’s particular Fields records or show Data in ListBox in VB.Net or Listing particular Field in List then here we use while loop without using ‘LIMIT’ in Query just same as bellow:

SQLite Select Query Example


VB:
MyListbox1.items.clear()
Dim SQLitecnStr As String ="Data Source=C:\MYSQLiteDBForVB.db; Integrated Security=true"
Dim SQLiteConn As New SQLiteConnection
Dim SQLitecmd As New SQLiteCommand
Dim SQLiteReader As SQLiteDataReader
SQLiteConn.ConnectionString = SQLitecnStr
SQLiteConn.Open()

SQLitecmd.Connection = SQLiteConn
SQLitecmd.CommandText = "SELECT * from MySQLiteTable;"
SQLiteReader = SQLitecmd.ExecuteReader()
 
While SQLiteReader.Read()
    MyListbox1.Items.Add(SQLiteReader("MyMono").ToString)
End While

SQLiteReader.Close()
SQLiteConn.Close()


C#:
MyListbox1.Items.Clear();
string SQLitecnStr = @"Data Source=C:\MYSQLiteDBForVB.db; Integrated Security=true";
SQLiteConnection SQLiteConn = new SQLiteConnection();
SQLiteCommand SQLitecmd = new SQLiteCommand();
SQLiteDataReader SQLiteReader;

SQLiteConn.ConnectionString = SQLitecnStr;
SQLiteConn.Open();

SQLitecmd.Connection = SQLiteConn;
SQLitecmd.CommandText = "SELECT * from MySQLiteTable;";
SQLiteReader = SQLitecmd.ExecuteReader();

while (SQLiteReader.Read())
    {
       MyListbox1.Items.Add(SQLiteReader["MyMono"].ToString());
    }

 SQLiteReader.Close();
 SQLiteConn.Close();


After executing this code, we will find following output.

Show SQLite Data in Listbox in VB.Net


(4) Show SQLite Data in ListView in VB.Net :

Now, Lets Learn about important point that we use in every simple programming process in vb.net or any other programming Languages. Here we will talk about ListView (Showing Multiple Rows with multiple columns) with containing SQLite Records in VB.Net

Here we learn how to Use SQLite in ListView in VB.Net. So we have to follow the code like:

VB:
MyLstView.Items.Clear()
Dim SQLitecnStr As String ="Data Source=C:\MYSQLiteDBForVB.db; Integrated Security=true"
Dim SQLiteConn As New SQLiteConnection
Dim SQLitecmd As New SQLiteCommand
Dim SQLiteReader As SQLiteDataReader

SQLiteConn.ConnectionString = SQLitecnStr
SQLiteConn.Open()

SQLitecmd.Connection = SQLiteConn
SQLitecmd.CommandText = "SELECT * from MySQLiteTable;"
SQLiteReader = SQLitecmd.ExecuteReader()

While SQLiteReader.Read()
    Dim Lstv As New ListViewItem
    Lstv.Text = SQLiteReader("MySrno").ToString
    Lstv.SubItems.Add(SQLiteReader("MyName").ToString)
    Lstv.SubItems.Add(SQLiteReader("MyMono").ToString)
    MyLstView.Items.Add(Lstv)
End While

SQLiteReader.Close()
SQLiteConn.Close()


C#:
MyLstView.Items.Clear();
string SQLitecnStr = @"Data Source=C:\MYSQLiteDBForVB.db; Integrated Security=true";
SQLiteConnection SQLiteConn = new SQLiteConnection();
SQLiteCommand SQLitecmd = new SQLiteCommand();
SQLiteDataReader SQLiteReader;

SQLiteConn.ConnectionString = SQLitecnStr;
SQLiteConn.Open();

SQLitecmd.Connection = SQLiteConn;
SQLitecmd.CommandText = "SELECT * from MySQLiteTable;";
SQLiteReader = SQLitecmd.ExecuteReader();

while (SQLiteReader.Read())
     {
        ListViewItem Lsvw = new ListViewItem();
        Lsvw.Text = SQLiteReader["MySrno"].ToString();
        Lsvw.SubItems.Add(SQLiteReader["MyName"].ToString());
        Lsvw.SubItems.Add(SQLiteReader["MyMono"].ToString());
        MyLstView.Items.Add(Lsvw);
     }

SQLiteReader.Close();
SQLiteConn.Close();


So, the output will displayed like below to showing SQLite Records in ListView in VB.Net.

 
SQLite Record in Listview in VB.Net



Here are the above given details with step by step points for Showing Data of SQLite in VB.Net. Try to implement more your project with above given examples.

Login Form in Python GUI with MYSQL and MSSQL Connection

In python, if we want to Design Login Form with database authentication with MYSQL or MSSQL then we have to follow the following process with step by step guide. 

Here we will learn How to Design Login Form in Python GUI with MYSQL connection in Python or SQL Server Connection in Python
Design Login Form in Python Tkinter


First we have to Create table For authentication with following field Name:
Login_tbl
usrname passwrd
sko tech

Same type of table we create in MSSQL. 

After that we will use following tkinter widget:
Name Tkinter Wiidget
Bannerlabel  Label
UserLabel  Label
PassLabel  Label
UserTxt  Entry
PassTxt  Entry
LoginBtn  Button

After that we will proceed with following points:

  1. Login Form Design in Python GUI with MYSQL Connection
  2. Login Form Design in Python GUI with MSSQL Connection

Now we will first Start with MYSQL connection then MS SQL Server Connection.

(1). Login Form Design in Python GUI with MYSQL Connection :

Now, first we will import ‘mysql.connector’ for connection. Then write code for establish connection with MYSQl after that write code for query like following way:

import mysql.connector as mysqlconnector
import tkinter as mytk
from tkinter import *
import tkinter.messagebox as mymessagebox

MyLoginForm = mytk.Tk()
MyLoginForm.title('Login Form with MYSQL Connection')
#Set Form Size
MyLoginForm.geometry("380x200")

def ClicktoLogin():
    #MYSQL ConnectionString
    mydb = mysqlconnector.connect(host="xxx.xxx.xxx.xx", user="sko", password="mypassword", database="skotechlearn")
    mycursor = mydb.cursor(dictionary=True)
    mycursor.execute("SELECT * FROM login_tbl where usrname = '"+ UserTxt.get() +"' and passwrd = '"+ PassTxt.get() +"';")
    myresult = mycursor.fetchone()
    if myresult==None:
       mymessagebox.showerror("Error", "Invalid User Name And Password")

    else:
       mymessagebox.showinfo("Success", "Successfully Login")
            
    mydb.close()
    mycursor.close()

# Set Tkinter Widget Size Location and Style
Bannerlabel = Label(MyLoginForm, text = "Login Form......", width=40, bg= 'yellow')
Bannerlabel.place(x=20, y=20)

UserLabel = Label(MyLoginForm, text = "User Name:", width=10)
UserLabel.place(x=20, y=60)

UserTxt = Entry(MyLoginForm,  width=27, relief="flat")
UserTxt.place(x=120, y=60)

#Set Focus on User Entrybox in Tkinter
UserTxt.focus()

PassLabel = Label(MyLoginForm, text = "Password :", width=10)
PassLabel.place(x=20, y=90)

PassTxt = Entry(MyLoginForm,  width=27, relief="flat")
PassTxt.place(x=120, y=90)

#Set Password Char in Entry Widget
PassTxt.config(show="*");

LoginBtn = Button(MyLoginForm, text ="Login", command = ClicktoLogin, relief="groove", fg='blue')
LoginBtn.place(x=280, y=140)

MyLoginForm.configure(background='#54596d')
MyLoginForm.mainloop()

When we execute this code. We will see the output looks like bellow.
 
Login Form MYSQL Connection in Python



As you can see we have changed Form, Label color for better look. After successful Login there will be a message displayed like above figure.
Now, Lets come to another point with MSSQL Connection in Python.

(2). Login Form Design in Python GUI with MSSQL Connection :

For MSSQL Connection first we install pymssql.
pip install pymssql

or
pip3 install pymssql

After that we will import pymssql in python code.
 
For Import and for MSSQL Connection String in Python, we will write following code.
 
MSSQL Server Connection in Python

Connection String Code:

# pymssql.connect(MSSQLServerIP, UserName, Password, Database)
pymssql.connect("xxx.xxx.xxx.xx", "myusername", "myPassword", "MyDatabase")


Let’s see how can we connect MSSQL Server with Python Tkinter Login Form?

import pymssql as MSSQLCnn
import tkinter as mytk
from tkinter import *
import tkinter.messagebox as mymessagebox

MyLoginForm = mytk.Tk()
MyLoginForm.title('Login Form with MSSQL Server Connection')
MyLoginForm.geometry("380x200")

def ClicktoLogin():
    #MSSQL Server ConnectionString
    MSSQLdb = MSSQLCnn.connect("xxx.xxx.xxx.xx", "SQLServerUser", "SQlServerPassword", "SQLServerDatabase")
    mySQLcursor = MSSQLdb.cursor()
    mySQLcursor.execute("SELECT * FROM login_tbl where usrname = '"+ UserTxt.get() +"' and passwrd = '"+ PassTxt.get() +"';")
    mySQLresult = mySQLcursor.fetchone()
    if mySQLresult==None:
       mymessagebox.showerror("Error", "Invalid User Name And Password")

    else:
       mymessagebox.showinfo("Success", "Successfully Login")
            
    MSSQLdb.close()
    mySQLcursor.close()

Bannerlabel = Label(MyLoginForm, text = "MSSQL Server Login Form......", width=40, bg= '#81907E', fg='white')
Bannerlabel.place(x=20, y=20)

UserLabel = Label(MyLoginForm, text = "User Name:", width=10, bg='#FFE6D8')
UserLabel.place(x=20, y=60)

UserTxt = Entry(MyLoginForm,  width=27, relief="flat")
UserTxt.place(x=120, y=60)

#Focus of User Entrybox in Tkinter
UserTxt.focus()

PassLabel = Label(MyLoginForm, text = "Password :", width=10, bg='#FFE6D8')
PassLabel.place(x=20, y=90)

PassTxt = Entry(MyLoginForm,  width=27, relief="flat")
PassTxt.place(x=120, y=90)

#Set Entry box Password Char in Tkinter
PassTxt.config(show="*");

LoginBtn = Button(MyLoginForm, text ="Login", command = ClicktoLogin, relief="groove", fg='blue')
LoginBtn.place(x=280, y=140)

MyLoginForm.configure(background='#FFE6D8')
MyLoginForm.mainloop()


After the execution of this code in python, the following output will present.

Login Form MSSQL Connection in Python


This way you can easily Create or Design Login Form in Python GUI with Tkinter and Connect Login Form with MSSQL in Python Or Connect Login Form with MYSQL in Python.