Python - How To Browse Image File And Display It In Python Tkinter

Python - How To Browse Image File And Display It Into Label Using Python Tkinter 

Browse Image File And Display It In Python Tkinter


In this Python Tutorial we will see How To Load A Picture To A Label using filedialog and  askopenfilename In Python Tkinter using VsCode .








Project Source Code:


import tkinter as tk
from tkinter import *
from tkinter import filedialog
from PIL import ImageTk, Image


root = Tk()

frame = tk.Frame(root, bg='#45aaf2')

lbl_pic_path = tk.Label(frame, text='Image Path:', padx=25, pady=25,
font=('verdana',16), bg='#45aaf2')
lbl_show_pic = tk.Label(frame, bg='#45aaf2')
entry_pic_path = tk.Entry(frame, font=('verdana',16))
btn_browse = tk.Button(frame, text='Select Image',bg='grey', fg='#ffffff',
font=('verdana',16))


def selectPic():
global img
filename = filedialog.askopenfilename(initialdir="/images", title="Select Image",
filetypes=(("png images","*.png"),("jpg images","*.jpg")))
img = Image.open(filename)
img = img.resize((200,200), Image.ANTIALIAS)
img = ImageTk.PhotoImage(img)
lbl_show_pic['image'] = img
entry_pic_path.insert(0, filename)


btn_browse['command'] = selectPic

frame.pack()

lbl_pic_path.grid(row=0, column=0)
entry_pic_path.grid(row=0, column=1, padx=(0,20))
lbl_show_pic.grid(row=1, column=0, columnspan="2")
btn_browse.grid(row=2, column=0, columnspan="2", padx=10, pady=10)

root.mainloop()


/////OUTPUT:

How To Browse Image File And Display It In Python Tkinter

How To Browse And Display Image In Python Tkinter





Inventory Management System Source Code

Download 5 Inventory Management System Source Code

Inventory Management System Source Code


inventory management system is one of the most popular projects beginners or intermediate programmers want to make.

to make this project you need to track stock, orders, sales and more to make it more advanced.

now let's see a list of inventory management systems in different programming language.


 1 - JAVA Inventory System Source Code 


inventory management system in java programming language using netbeans ide and mysql database.






 2 - C# Inventory System Source Code 


inventory management system in c# programming language using visual studio and sql server database.





 3 - VB.Net Inventory System Source Code 


inventory management system in visual basic .net programming language using visual studio and mysql database.





 4 - PHP Stock Manager Advance with Point of Sale Module Source Code 


web application to manage sales and inventory on site in php programming language using codeIgniter framework and mysql database.



 5 - Python Inventory System Source Code 


inventory management system in python programming language using tkinter and mysql database in VsCode.






Python And MySQL - How To Insert Data Into MySQL Database Using Python Tkinter

Python - How To Add Records to a MySQL Database Using Tkinter Python


How To Insert Data Into MySQL Database Using Python Tkinter


in this Python Tutorial we will see how to Insert user inputs to a MySQL database table using 
Python Tkinter.







Project Source Code:


import tkinter as tk
from tkinter import *
from tkinter import ttk
import mysql.connector

root = Tk()
root.title("Insert Data")

connection = mysql.connector.connect(host='localhost', user='root', password='',
port='3306', database='test_py')
c = connection.cursor()

bkg = "#636e72"


frame = tk.Frame(root, bg=bkg)

label_firstname = tk.Label(frame, text="First Name: ", font=('verdana',12), bg=bkg)
entry_firstname = tk.Entry(frame, font=('verdana',12))

label_lastname = tk.Label(frame, text="Last Name: ", font=('verdana',12), bg=bkg)
entry_lastname = tk.Entry(frame, font=('verdana',12))

label_email = tk.Label(frame, text="Email: ", font=('verdana',12), bg=bkg)
entry_email = tk.Entry(frame, font=('verdana',12))

label_age = tk.Label(frame, text="Age: ", font=('verdana',12), bg=bkg)
entry_age = tk.Entry(frame, font=('verdana',12))


def insertData():
firstname = entry_firstname.get()
lastname = entry_lastname.get()
email = entry_email.get()
age = entry_age.get()

insert_query = "INSERT INTO `users_2`(`firstname`, `lastname`, `email`, `age`)
VALUES (%s,%s,%s,%s)"
vals = (firstname,lastname,email,age)
c.execute(insert_query,vals)
connection.commit()


button_insert = tk.Button(frame, text="Insert", font=('verdana',14), bg='orange',
command = insertData)

label_firstname.grid(row=0, column=0)
entry_firstname.grid(row=0, column=1, pady=10, padx=10)

label_lastname.grid(row=1, column=0)
entry_lastname.grid(row=1, column=1, pady=10, padx=10)

label_email.grid(row=2, column=0, sticky='e')
entry_email.grid(row=2, column=1, pady=10, padx=10)

label_age.grid(row=3, column=0, sticky='e')
entry_age.grid(row=3, column=1, pady=10, padx=10)

button_insert.grid(row=4,column=0, columnspan=2, pady=10, padx=10, sticky='nsew')

frame.grid(row=0, column=0)


root.mainloop()


OUTPUT:
insert data into mysql database using python in tkinter







C# - Create Glass Bridge Game In C#

How To Create Glass Bridge Game From Squid Game Using C#

Glass Bridge Game In C#


in this c# form tutorial we will see how to make The Glass Stepping Stones Game or the Glass Bridge Game From Squid Game using panels and pictureboxes in csharp programming language.

game rules:
- the player have to hop across a bridge of glasses with some glasses that breack easily.

tools:
- c# programming language.
- microsoft visual studio express 2013.
- pixabay.com (images).

Watch This Full Demo



- The Project Source Code


using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace csharp_glass_bridge
{
    public partial class Game_Form : Form
    {
        public Game_Form()
        {
            InitializeComponent();
        }

        // images
        Bitmap step = Properties.Resources.step;
        Bitmap nostep = Properties.Resources.nostep;

        // random to get random images
        Random random = new Random();
        Bitmap randomImage;

        // arraylist of pictureboxes
        PictureBox[,] picBoxes;
        // populate this array with random images
        // 6 - number of rows
        // 2 - number of columns
        Bitmap[,] imagesOrder = new Bitmap[6, 2];
        ArrayList list = new ArrayList();
        int counter = 0;
        bool won = true;

        private void Game_Form_Load(object sender, EventArgs e)
        {
            pictureBoxStart.Image = step;

            // populate the picBoxes with pictureboxes
            picBoxes = new[,] {{ pictureBox_1_1, pictureBox_1_2 },{ pictureBox_2_1, pictureBox_2_2 },
                               { pictureBox_3_1, pictureBox_3_2 },{ pictureBox_4_1, pictureBox_4_2 },
                               { pictureBox_5_1, pictureBox_5_2 },{ pictureBox_6_1, pictureBox_6_2 }
            };

            // add images to the list
            list.Add(step);
            list.Add(nostep);

            createRandomImages();

            AddEventToAllPictureboxes(null, null);

            enablePicBox(counter);

        }

        // button to restart the game
        private void buttonRestart_Click(object sender, EventArgs e)
        {
            createRandomImages();
            won = true;
            counter = 0;
            label_message.Text = "";
            enablePicBox(counter);
            pictureBoxFinish.Image = null;
            foreach(PictureBox pbox in picBoxes)
            {
                pbox.Image = null;
            }
        }


        // create a function to get random images
        public void createRandomImages()
        {
            for(int i = 0; i < 6; i++)
            {
                randomImage = (Bitmap)list[random.Next(list.Count)];
                imagesOrder[i, 0] = randomImage;

                if(randomImage.Equals(step))
                {
                    imagesOrder[i, 1] = nostep;
                }
                else
                {
                    imagesOrder[i, 1] = step;
                }
            }
        }


        // create an event click to all the pictureboxes in panel top
        public void paneltop_picBoxes_click(object sender, EventArgs e)
        {
            PictureBox pbox = (PictureBox)sender;
            if(pbox.Enabled)
            {
                pbox.Image = imagesOrder[counter, 1];

                // disable picturebox
                pbox.Enabled = false;
                picBoxes[counter, 0].Enabled = false;

                if (imagesOrder[counter, 1].Equals(nostep))
                {
                    won = false;
                }
                if (counter == 5 && won == true)
                {
                    pictureBoxFinish.Image = step;
                    label_message.Text = "You've Won";
                }
                else if (won == false)
                {
                   // MessageBox.Show("You've Lost");
                    label_message.Text = "You've Lost";
                }

                counter++;
                enablePicBox(counter);
            }
            
        }


        // create an event click to all the pictureboxes in panel bottom
        public void panelbottom_picBoxes_click(object sender, EventArgs e)
        {
            PictureBox pbox = (PictureBox)sender;
            if (pbox.Enabled)
            {
                pbox.Image = imagesOrder[counter, 0];

                // disable picturebox
                pbox.Enabled = false;
                picBoxes[counter, 1].Enabled = false;

                if (imagesOrder[counter, 0].Equals(nostep))
                {
                    won = false;
                }
                if (counter == 5 && won == true)
                {
                    pictureBoxFinish.Image = step;
                    label_message.Text = "You've Won";
                }
                else if (won == false)
                {
                    //MessageBox.Show("You've Lost");
                    label_message.Text = "You've Lost";
                }

                counter++;
                enablePicBox(counter);
            }
            
        }

        // add event to all the pictureboxes
        public void AddEventToAllPictureboxes(object sender, EventArgs e)
        {
            foreach(Control c in panel_top.Controls)
            {
                if(c is PictureBox)
                {
                    c.Click += new System.EventHandler(paneltop_picBoxes_click);
                }
            }

            foreach (Control c in panel_bottom.Controls)
            {
                if (c is PictureBox)
                {
                    c.Click += new System.EventHandler(panelbottom_picBoxes_click);
                }
            }
        }


        // create a function to enable picturebox
        public void enablePicBox(int index)
        {
            if(index <= 5)
            {
                picBoxes[index, 0].Enabled = true;
                picBoxes[index, 1].Enabled = true;
            }
            
        }
    }
}


OUTPUT:
Create Glass Bridge Game In C#

Glass Bridge Game In C#

Glass Stepping Stones Game In C#

Glass Stepping Stones Game Source Code In C#