Trending February 2024 # Syntax And Different Examples Of Jquery Innerwidth() # Suggested March 2024 # Top 8 Popular

You are reading the article Syntax And Different Examples Of Jquery Innerwidth() updated in February 2024 on the website Bellydancehcm.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested March 2024 Syntax And Different Examples Of Jquery Innerwidth()

Introduction to jQuery innerWidth()

jQuery innerWidth() is an inbuilt jQuery method. It gives the current computed inner width for the first matched element and sets the width for each matched element. This method is supported by browsers- Google Chrome, Internet Explorer, Firefox, Opera, Safari.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The method innerWidth() method includes the padding value but excludes the margin and border value as represented in the below diagram.

Syntax of jQuery innerWidth()

Syntax Parameter Description Value Type Version

$(selector).innerWidth() NA NA 1.0

$(selector). innerWidth (Value) 1. Value: A numerical value as the measurement value. 1. Handler: String/Number 1.8.0

$(selector). innerWidth (Function) 1. Function: To set the width of the matched element whose index is given as an input argument. 1. Function: Function 1.8.0

Examples of jQuery innerWidth()

Given below are the examples of jQuery innerWidth():

Example #1: Without using any parameter

innerWidth() method can be used without providing any input argument. It is used to get the width measurement for the first matched element including the padding value. This method without input argument becomes a read-only property of the window.

Code:

<script type = ”text/javascript” $(document).ready(function() { var color = $(this).css(“background-color”); var width = $(this).innerWidth(); $(“#result”).css({‘color’: color, ’background-color’:’white’}); }); }); #div1 { margin:10px;padding:12px; border:3px solid #666; width:60px;} #div2 { margin:15px;padding:6px; border:5px solid #666; width:60px;} #div3 { margin:20px;padding:12px; border:3px solid #666; width:60px;} #div4 { margin:15px;padding:6px; border:5px solid #666; width:60px;}

Output:

Before innerWidth() method is called:

After innerWidth() method is called:

Example #2: With the ‘value’ parameter

For jQuery innerWidth(), a value of type string or number can be given as input argument value. This syntax can be used to modify the width of the selected element to the value that is passed to the method as input argument value.

Code:

$(document).ready(function(){ $(“div”).innerWidth(500) $( ”p” ).text( ”InnerWidth for div session:” + $( ”div” ).innerWidth() ); }); });

Output:

Before innerWidth() method is called:

After innerWidth() method is called:

Note: For the syntax innerWidth(value), if a number is provided as value, jQuery treats in terms of pixel unit by default unless any specific unit is not mentioned. If a string value is provided, any CSS measurement can be used for the width value.

Example #3: innerWidth() With ‘function’ parameter

In this syntax, the method innerWidth() accepts function as input argument. This syntax of innerWidth() method accepts any function that is with or without input arguments.

Code:

//The width of the div element is decided by the function output of myfunc() and $(document).ready(function(){ $(“div”).innerWidth(myfunc()); $( ”p” ).text( ”InnerWidth for div session:” + $( ”div” ).innerWidth()); }); }); function myfunc() { return 100+$( ”div” ).innerWidth() }

Output:

Before innerWidth() method is called:

After innerWidth() method is called:

Screen 1: myfunc method is called once.

Screen 2: myfunc method is called twice.

Additional Note

This method returns the value of the inner width in terms of pixels.

In the case of an empty set of elements, the method gives the result as ‘undefined’.

This method does not support .doc or window object. For such an object. width() method is used.

The resultant value can be fractional as well. If the code takes the round value for the result, it may give incorrect dimensions for the site in the zoomed condition as the browser may not include any API to detect such condition.

If the matched element or its parent element is in hidden state, innerWidth() may not give an accurate result. In order to avoid such erroneous result, it is required to ensure the visibility state of the element to be true then revert back to the hidden state after the method execution is completed. Though it works for accuracy, still reliability of this approach is under question mark.

InnerWidth(), OuterWidth() and Width() are similar to each other. They are different from each other in terms of inclusion or padding, margin and border values. InnerWidth() includes padding value only where as OuterWidth() includes both padding and border value. Width() does not consider only element width.

Recommended Articles

This is a guide to jQuery innerWidth(). Here we discuss the introduction, syntax, and examples of jQuery innerWidth(). You may also have a look at the following articles to learn more –

jQuery remove()

jQuery wrapInner()

jQuery fadeIn()

jQuery appendTo()

You're reading Syntax And Different Examples Of Jquery Innerwidth()

Definition And Syntax With Examples

Definition of MySQL AES_Encrypt

The MySQL AES_Encrypt function implements the AES algorithm to encode a provided string as arguments. The AES algorithm, which stands for Advanced Encryption Standard, encrypts the data using a key length of 128 bits, extendable up to 256 bits. MySQL AES_Encrypt() encodes a specific string and produces a binary series. If the argument provided to the function is NULL, the output will also be NULL.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

We, a user, provide too small a key length. It may be null-padded, i.e., due to the memset, but if it’s too big, then it may xor the additional bytes using the first key_size bytes; suppose when the critical size will be 4bytes along with the key as 12345678, then it will be xor to 5678 using the outcome as the key with 1234. Therefore, for the best security, we must implement a random key length of the size configured AES to be used. Hence, for providing AES-128, we need a 128-bit as a random key or 32 hex characters.

Syntax of MySQL AES_Encrypt AES_ENCRYPT (Encryp_String, Key_String);

The function named Encryp_String describes the arguments mentioned above, which are Encryp_String and Key_String.

Encryp_String:  This string will be encrypted.

Key_String: This is the key string to encrypt the first argument String.

These input arguments can be of any length. If any of these arguments, such as the key value or the string to be encrypted, are NULL, the function will return NULL. AES is an algorithm that operates at the block level, where padding encodes strings of irregular lengths. The resulting length of the string can be calculated using the following formula:

16 * (trunc(str_len/16) + 1);              

AES is a two-way encryption and decryption mechanism that provides security for sensitive data records while allowing the original data to be retrieved. The AES algorithm utilizes an encryption key as a seed to achieve this. AES implements a compound mathematical algorithm comprising two concepts: confusion and diffusion. Here, the confusion process helps to hide the relationship between the original data and the encrypted data result. In contrast, the Diffusion process functions to shift, alter or adjust the data compositely.

When executed, the function AES_ENCRYPT() in MySQL will return the value, which is a binary string, after converting the original plaintext. The MySQL AES_ENCRYPT() function supports MySQL versions 5.7, 5.6, 5.5, 5.1, 5.0, and 4.1.

How does AES_ENCRYPT Function Work in MySQL?

AES_ENCRYPT() function in MySQL applies encryption of data records by using the official AES algorithm, formerly recognized as ‘Rijndael’, where the AES standard allows several key lengths. The default key length is 128 bits, but 196 and 256 bits can also be implemented as described. The key length in AES is a trade-off between safety and performance.

Let us view the code example to show the working of the AES_Encrypt() function as below:

SELECT AES_Encrypt('mysqlcoding','mysqlkeystring');

The above MySQL query statement encodes the string specified like ‘mysqlcoding’ with the key mysqlkeystring. The output for this will be the following after execution:

AES_Encrypt() allows the regulator of the block encryption mode and will receive init_vector as an optional initialization vector argument where:

This system variable block_encryption_mode governs the mode for the server’s block-based encryption algorithms whose value is aes-128-ecb by default, indicating encryption using a key length of 128 bits and mode ECB.

The optional argument init_vector delivers an initialization vector for this block encryption mode, which needs it.

Modes that require the init_vector argument should have a length of 16 or more bytes, with any bytes beyond 16 being ignored. But an error will take place if init_vector is missing. So we can write as follows:

SELECT AES_ENCRYPT (Encryp_String, Key_String, @init_vector);

But the modes that do not need the optional argument init_vector will be disregarded, and an associated warning is produced if it is stated.

To use an initialization vector (IV), a random string of bytes can be generated by invoking RANDOM_BYTES(16). When the encryption mode requires an IV, you should consistently use the generated vector for the encryption and decryption of any string.

Certainly! Below is a table list that explains various allowed block encryption modes along with the associated initialization vector (IV) argument required:

Block Encryption Mode  Initialization Vector Needed

ECB No

CBC Yes

CFB1 Yes

CFB8 Yes

CFB128 Yes

OFB Yes

Examples of MySQL AES_Encrypt

Let us illustrate some examples to show the MySQL AES_Encrypt() function works as follows:

1. Executing AES_Encrypt() function on a string by SELECT statement:

SELECT AES_ENCRYPT('XYZ','key');

The MySQL AES_Encrypt() uses the SELECT statement to find the outcome and encrypt the string in the MySQL server.

Output:

2. Executing AES_Encrypt() function on a bigger string by SELECT statement:

SELECT AES_ENCRYPT('MySQLdatabasefunction','key');

Output:

SELECT AES_ENCRYPT(NULL,'key');

Output:

4. Executing AES_Encrypt() function implementing a sample table in the database:

INSERT INTO demo VALUE (AES_ENCRYPT('mystring','key'));

If explained in the above query, the function encrypts the particular string mystring with a key and enters the encrypted string as output into the table ‘demo’.

5. Executing AES_ENCRYPT() function with key value:

SELECT AES_ENCRYPT('All is Well','Google');

Output:

The AES_ENCRYPT() function accepts the key value “Google” and the string to be encrypted, “All is Well,” as arguments.

Conclusion

The MySQL AES_ENCRYPT() function is considered insecure because it defaults to using ECB mode unless configured otherwise.

Depending on what the server’s block_encryption_mode a user configures, we can use the key length from the list of supported ones, such as 128, 256, and 192, where the AES standard algorithm also permits these key lengths.

Recommended Articles

We hope that this EDUCBA information on “MySQL AES_Encrypt” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Keycodes Table And Examples Of Jquery Keycode

Introduction to jQuery keycode

jQuery key code is used to the mapping of keycodes to their numeric values. Key codes are the keyboard keys to which have digital values mapped to the keys based on the key code description. jQuery keycode is a part of Themes in jQuery UI API category, there are many more API’s like disableSelection(), enableSelection(), .uniqueId(), .zIndex(), .focus() provided by chúng tôi function in jQuery UI. This jQuery UI was built upon jQuery JavaScript’s library for User Interface, Effects, Themes, Widgets, and User Interaction. The recommended version of jQuery UI is v1.10. Let’s have a look at Syntax and how jQuery keycodes work.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax:

jQuery.ui.keyCode

Before getting into examples of jQuery keycode, we need to know KeyCodes Table.

KeyCode Description/ Numeric value

Backspace 8

Tab 9

Enter 13

Shift 16

CTRL 17

ALT 18

Pause/ Break 19

Caps Lock 20

ESC 27

Page Up 33

Page Down 34

End 35

Home 36

Arrow Left 37

Arrow Up 38

Arrow Right 39

Arrow Down 40

Insert 45

Delete 46

0 48

1 49

2 50

3 51

4 52

5 53

6 54

7 55

8 56

9 57

;: 59

=+ 61

a 65

b 66

c 67

d 68

e 69

f 70

g 71

h 72

i 73

j 74

k 75

l 76

m 77

n 78

o 79

p 80

q 81

r 82

s 83

t 84

u 85

v 86

w 87

x 88

y 89

z 90

Windows 91

93

0(Num Lock) 96

1(Num Lock) 97

2(Num Lock) 98

3(Num Lock) 99

4(Num Lock) 100

5(Num Lock) 101

6(Num Lock) 102

7(Num Lock) 103

8(Num Lock) 104

9(Num Lock) 105

*(Num Lock) 106

+(Num Lock) 107

-(Num Lock) 109

.(Num Lock) 110

/(Num Lock) 111

F1 112

F2 113

F3 114

F4 115

F5 116

F6 117

F7 118

F8 119

F9 120

F10 121

F11 122

F12 123

Num Lock 144

Scroll Lock 145

My Computer 182

My Calculator 183

,< 188

190

/? 191

`~ 192

[{ 219

220

]} 221

‘” 222

Examples of jQuery keycode

Here are the following examples mention below

Example #1

jQuery keycode with onkeypress()

function sampleKeyCode(event) { var keycode = (event.keyCode ? event.keyCode : event.which); document.getElementById(“demoKey”).innerHTML = “The Numeric value is: ” + keycode; }

Output:

On entering any key value, for, e.g. Entering ‘A’, the numerical value for ‘A’ is 65, as shown below.

On entering ‘b’, the numerical value for ‘b’ is 98. (onKeyPress) as shown below. If onKeyDown, the value of ‘b’ will be 66.

On entering the ‘Enter’ key, the value of the ‘Enter’ key is 13, as shown below

Example #2

jQuery keyCode with onKeydown().

function sampleKeyCode(event) { var keycode = (event.keyCode ? event.keyCode : event.which); document.getElementById(“demoKey”).innerHTML = “The Numeric value is: ” + keycode; }

// The only difference between Example 1 and Example 2 here are the key events. In the previous example, we used onKeypress(), now we have used onKeydown().

On entering value ‘b’, the numeric keycode is 66, as shown below

Example #3

jQuery keyCode: key-value based on numeric value

function sampleKeyCode(event) { var keycode = (event.keyCode ? event.keyCode : event.which); if(keycode == ’13’){ alert(‘You pressed a “enter” key in textbox’); } else if(keycode == ’45’){ alert(‘You pressed a “Insert” key in textbox’); } else if(keycode == ‘9’){ alert(‘You pressed a “Tab” key in textbox’); } else if(keycode == ’48’){ alert(‘You pressed a “0” key in textbox’); } else if(keycode == ’90’){ alert(‘You pressed a “z” key in textbox’); } else if(keycode == ‘112’){ alert(‘You pressed a “F1” key in textbox’); } else if(keycode == ‘219’){ alert(‘You pressed a “[ or {” key in textbox’); } else{ alert(‘You pressed some other key in textbox’); } }

Output:

On pressing the ‘Insert’ key,

On pressing ‘Enter’,

On pressing any other key,

As the keycode returns the Unicode character code of the key that is triggered here on the keypress event, we have two types of code types:

Character codes and  Key Codes: Key codes represent the actual key of the keyboard, whereas Character code represents ASCII character.

Conclusion

With this, we conclude the topic ‘jQuery keycode’, we have seen what jQuery keycode and its syntax is and how it is used to get the keyCode of a particular keyboard value. Listed out the keyCodes for maximum keys of the keyboard. So that you can have this table or refer and try to give some hands-on this topic. Explained a few examples also can be useful to find out key codes or the Unicode character codes. We have 3 events here, onKeydown(), onKeyup(), or onKeypress(), examples above shown are using onKeypress() and onKeydown() events.

Recommended Articles

This is a guide to jQuery keycode. Here we discuss the Examples of jQuery keycode along with the codes and outputs and how it is used to get the keyCode of a particular keyboard value. You may also have a look at the following articles to learn more –

Usage And Different Examples Of Sql Max()

Introduction to SQL MAX()

SQL MAX() is one of the aggregate functions available in SQL that helps us fetch the greatest value among multiple values specified in the column values of records, the expression consisting of the column that is mentioned. When a query is used to retrieve the data that report related and contains a group by a statement, the MAX() function is used to get the greatest value of a particular column or columns based on the grouping function.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax and Usage

The syntax of the MAX function in SQL is given below:

SELECT MAX(expression) FROM table_name [WHERE restriction];

Where expression can be any name of the column of the table or a formula built up using column names and static literal values or variables, the table_name is the name of the table from which you want to retrieve the records and calculate the greatest value from one of their columns. The use of the FROM table name clause is required. One optional thing is the use of a where clause to mention the conditions and restrictions that the records of the table should fulfil to consider that record’s column value for fetching the greatest value.

Examples of SQL MAX()

Given below are the examples of SQL MAX():

Example #1 – Using a single column.

Let us firstly consider a simple example that we used above. We will calculate the greatest value of SQL numbers using the MAX() function. Let us create one simple table named numbers and store the num column value in it.

We will use the following query statement to create our table.

Code:

CREATE TABLE numbers (num INT) ;

Now, we will insert the above records in the table.

Code:

INSERT INTO numbers(num) VALUES (50), (100), (150), (200);

Let us now retrieve the records once.

Code:

SELECT * FROM numbers ;

Output:

Now, we will calculate the greatest of num column of numbers table using MAX() function using the following query statement.

Code:

SELECT MAX(num) FROM numbers ;

Output:

Example #2 – Using the distinct function.

We can use the distinct function in MAX() function to consider the column’s repetitive values only once while fetching the greatest value. Suppose that we insert some more records in the numbers table using the following query statement.

Code:

INSERT INTO numbers(num) VALUES (350), (800), (150), (300),(450), (100), (250); select * from numbers;

If we use SELECT MAX(num) FROM numbers; statement to calculate the greatest value of num column, then each of the values will be considered while fetching the greatest value.

Code:

SELECT MAX(DISTINCT(num)) FROM numbers ;

The output will be the same as that of the first query without a distinct function but internally the calculation of greatest value by MAX() function will only consider the column values that are repeated such as 100 and 150 only once.

The output of both of the above queries is as shown below.

Output:

Example #3 – Using formula.

We can use the MAX() function expressions to consider the value evaluated by fetching each of the formula or expression values containing column value to calculate the greatest value.

Let us consider one example; we will calculate the greatest of all the columns after they are multiplied by 10 and added by 1.

Code:

SELECT MAX((num * 10) + 1) FROM numbers ;

Output:

We can even use the existing functions such as SUM() and COUNT() inside the MAX() function.

Example #4 – Using group by.

When we have complex tables and relations between multiple tables, we have to query those tables using joins to retrieve data, usually for reporting purposes that consist of summarized data. Even in some scenarios, the data from a single table need to be manipulated to get summarized data. Suppose that we have one table named workers consisting of the following records in it that are retrieved by executing a simple select query on that table.

Code:

SELECT * FROM workers;

Output:

Now, the situation is such that we have to calculate the greatest salary of the workers per team. The output should consist of the team id and the greatest salary of that team. For this, we will have to use the group by statement and group the records based on team id and calculate the greatest salary by using MAX() function.

Code:

SELECT team_id, MAX(salary) FROM workers GROUP BY team_id ;

The execution of the above query statement will give the following output along with team ids and their respective greatest salaries.

Output:

Conclusion

We can use the MAX() function in SQL to fetch the greatest value of the columns of the tables or greatest of expressions that involve column values and even calculate the greatest value of columns in the grouped manner using the GROUP BY statement.

Recommended Articles

We hope that this EDUCBA information on “SQL MAX()” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Learn The Different Examples Of Python Widgets

Introduction to Python Widgets

Widgets are small parts on web applications that allow user input. The widgets are eventful objects of Python that have a browser representation, often as control such as a slider, textbox, etc. Interactive GUIs for Python notebook are created using these Widgets. Synchronize stateless and stateful information between JavaScript Python and is done using widgets. Widget input allows us to add parameters and dashboards to the notebooks. Widget API has calls that can be given with various types of input, access bound values, and removing them. Exploration of different parameters using a single query are the results of widgets. Widgets are of many types. Few are Text, drop down, Combo box, Multi-select, which are widely used. All these widgets are quiet neat to understand and implement.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax of Widgets

import widget_name

Example:

Ipywidgets packages furnish a lot of common interface controls. These interfaces are used in exploring code and data interactively. These can be customised and assembled for creating user interfaces that are complex. Let’s see various schemes to create user interfaces using Python Ipywidgets. The package of widgets in Python can be installed in Anaconda by default. Manual installation is done with conda install Ipywidgets. Or you can also use pip install Ipywidgets, but then an extension for Jupyter Notebook is needed.

Now, getting into the actual methodology:

The block of code shows how we import the widgets. These are few widgets which are used in general.

Code:

import Ipywidgets as widgets from Ipywidgets import Hbox, Vbox import numpy as np import matplotlib.pyplot as plt from Ipython.display import display %matplotlib inline Examples of Python Widgets

Widgets have an @interact decorator, which controls the function of arguments. The f() function receives an integer as an argument. That displays a slider by default.

Example #1

Displaying a slider which has border values and can be slid along, which is an integer slider.

Code:

import Ipywidgets as wg import Ipython.display name = chúng tôi (value = ‘Name’) age = wg.IntSlider (description = ‘Age: ’) display (name, age) print (name.value + ‘ is already ‘+ str (age.value) + ‘ now ’)

Output:

The above displays an age bar or a slider, where you can slide the age of John and hold at one. It is still changeable. At age.value, you need to consider taking the value as a string as it is a number or integer, and it needs to be typecasted because all the other parameters in the command line are integers.

You can also import the FloatText widget, which is the same as above but includes a floating-point slider. Wg.FloatText() is used.

Example #2

Code:

import numpy as np %matplotlib inline From matplotlib.pyplot as plt def myPlot (c): x = np.linspace(-5,5,20) y = c * x**2  # we are going to have a parabola here. plt.plot (x, y, ‘ r-- ‘) # let us make a plot using x and y values plt.ylabel (‘ y (x) ’) # create y label and make It y (x) plt.xlabel (‘ x ‘) # x label and named it x plt.ylim([ 0, 80 ]) plt.xlim ([ -5, 5 ])

myPlot(10) #running the plot with a random value.

Output:

But our point is to see the plot change with respect to c.

For that, we include a cSlider which sides along with the possible given values and updates the plot automatically. We can give a FloatSlider as well.

Code:

c_slide = wg.FloatSlider ( value = 1.0, min = 0.5, max = 3.5, steps = 0.2 ) #Then run the function by calling myPlot and include parameters to use. wg.interact (myPlot, c = c_slide)

Output:

c_slide.key: This is the keywords which display all the different types of widgets you might want to change. This will display quiet a big list.

wg.Widgets.widget_types: This is the keyword used to displays all the types of Widgets that can be used.

Example #3

Code:

import time progress = wg.IntProgress ( description = ‘ Loading: ’ ) progress.orientation = ‘horizontal’ #we can use vertical as well. display(progress) for i in range (100) progress.value = i time.sleep (0.1)

Output:

The loading bar in the above block of code can be taken as vertical, which shows a vertical orientation.

Try typing “import this” on Python IDE; you’ll find a poem highlighting the philosophies of Python.

Output:

Conclusion

Demonstration of many features of packages is done by importing Ipywidgets. Widgets can be styled and customised. They can be created using JavaScript and Python Notebook – Jupyter in this case. If you remove the keyword widget in case the same cell cannot be accessed, create subsequent command. Nevertheless, a widget can be created in another cell.

Recommended Articles

This is a guide to Python Widgets. Here we discuss the introduction to Python Widgets along with the examples, respectively. You may also have a look at the following articles to learn more –

Different Methods Of Tkinter Icon With Examples

Introduction to Tkinter Icon

Python encompasses various libraries that serve different purposes. Among them is Tkinter, a library employed in Python for constructing Graphical User Interfaces (GUIs). Tkinter is the easiest and fastest way to create Graphical User Interfaces in Python, and it also provides an object-oriented interface to the Tk GUI toolkit, which is very powerful. Tkinter icon is a way to put up our own customized icon on the different windows created by Tkinter. It is one of the most important parts of creating a Graphical User Interface. This article represents the different methods of the Tkinter icon and how it can be used in the different aspects of a GUI.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax:

Iconphoto() Method

iconphoto(self, default = False, *args)

Iconbitmap Method

call() Method

Methods of Tkinter Icon

Lets us discuss methods with Examples and their working:

 1. Iconphoto() Method

This method places a title bar icon on any top-level window. For setting up an image as the icon, the image needs to be an object of PhotoImage class.

Image used in example [i] & example [ii]-

Image used in example [iii]-

 [i] Basic Iconphoto() Usage Example

This is a basic example of creating a top-level window and putting up an image as its icon.

Code:

# Firstly import Tkinter Module from tkinter import * from chúng tôi import * import tkinter as tk # Then create a program Tkinter window program = Tk() # Photoimage class is created # And Image should be in the same folder where there is script saved p1 = PhotoImage(file = 'C:/Users/afu/Desktop/tk/Git.png') # Icon set for program window program.iconphoto(False, p1) # Button creation b = Button(program, text = 'Press Me!') b.pack(side = TOP) program.title('iconphoto() method') mainloop()

Output:

[ii] Advance Iconphoto() Usage Example

Code:

# Firstly import Tkinter Module from tkinter import * from chúng tôi import * from tkinter import Button import tkinter as tk # Then create a program Tkinter window program = Tk() # Photoimage class is created # And Image should be in the same folder where there is script saved p1 = PhotoImage(file = 'C:/Users/afu/Desktop/tk/Git.png') # Icon set for program window program.iconphoto(False, p1) # Button creation b = Button(program, text = 'Press Me!') b.pack(side = TOP) class Icon(Frame): def __init__(code): super().__init__() code.UI() def UI(code): framedesign = Frame(code, borderwidth=10) framedesign.pack() button1 = Button(framedesign, activebackground = 'SlateGray3', text='Change my color', bg = 'red') button1.pack(padx=5, side=LEFT) label1 = Label(framedesign, background='SlateGray3', width = 15) label1.pack(padx=5, side=LEFT) button2 = Button(framedesign, text='Mine too',background='blue', activebackground = 'SlateGray3') button2.pack(side=LEFT) label2 = Label(framedesign, background='SlateGray4',width = 15) label2.pack(side=LEFT) button3 = Button(framedesign, text='I am Green', background='crimson', activebackground = 'DarkSeaGreen3' ) button3.pack(side=RIGHT, padx=5) label3 = Label(framedesign, background='DarkSeaGreen3',width = 15) label3.pack(side=RIGHT, padx=5) button4 = Button(framedesign, text='Me too', background='pink',activebackground = 'DarkSeaGreen4') button4.pack(side=RIGHT) label4 = Label(framedesign, background='DarkSeaGreen4', width = 15) label4.pack(side=RIGHT) code.master.title("Advance iconphoto() method'") code.pack(fill=BOTH) code.pack() app = Icon() program.mainloop()

Output:

[iii] Advance Iconphoto() usage example with texts using multiple fonts

This example represents a way to create a window that sets up an image as its icon using an icon photo, and it also represents a way to set up different fonts in a window.

Code:

import tkinter as tk from tkinter import Tk from tkinter import BOTH from chúng tôi import Frame from chúng tôi import Label , Style from chúng tôi import Notebook program = tk.Tk() program.iconphoto(False, tk.PhotoImage(file='C:/Users/afu/Desktop/tk/Folder.png')) from chúng tôi import Font class Icon(Frame): def __init__(code): super().__init__() code.UI() def UI(code): code.master.title("program.iconphoto method example") code.pack(fill=BOTH, expand=True) text = "This example if for creating an icon " text1 = 'using program.iconphoto' text2 = 'Hope you like it' thefont = Font(family="Arial", size=16) label1 = Label(code, text=text, font=thefont) label1.grid(row=0, column=0) label2 = Label(code, text=text1, font="Times") label2.grid(row=1, column=0) label3 = Label(code, text=text2, font=('Courier', '18', 'bold')) label3.grid(row=2, column=0) app = Icon() program.mainloop()

 Output:

 2. Iconbitmap Method

For using this method, the bitmap image should be an icon type with .ico as its extension.

[i] Basic Iconbitmap Usage Example

This is a basic example of creating a window where the icon has been set using iconbitmap. As you can see, the image is of .ico extension, and using an icon-type image in this method is mandatory.

Code:

import tkinter as tk program = tk.Tk() program.title('iconbitmap method basic example') #Setting Icon for window widget program.iconbitmap('New.ico') program.mainloop()

Output:

[ii] Advance Iconbitmap Usage Example with Different Messages on pressing Buttons

This example shows us how to create a window with a bitmap image as its icon and buttons that display messages or ask questions when it is pressed. This example also explains how to make the window more responsive to questions and messages.

Code:

import tkinter as tk from tkinter import Frame, Tk from tkinter import Button from tkinter import LEFT, messagebox from tkinter import BOTH program = tk.Tk() program.iconbitmap('New.ico') #Setting Icon for window widget class Icon(Frame): def __init__(code): super().__init__() code.UI() def UI(code): framedesign = Frame(code, borderwidth=10) framedesign.pack() def Result(): tk.messagebox.showinfo( "Info", "Advance iconbitmap usage") def End(): MsgBox = tk.messagebox.askquestion ('End','Have you understood this program',icon = 'warning') if MsgBox == 'yes': program.destroy() else: tk.messagebox.showinfo('Return','Check our courses on Python on EduCBA') def Thanks(): tk.messagebox.showinfo( "Thanks", "Bbye, All the best for your future") button1 = tk.Button(framedesign, text='Know about me', command = Result, activebackground = 'Cyan') button1.pack(padx=5,side=LEFT) button2 = Button(framedesign, text='Question', width=8, command = End, activebackground = 'Cyan') button2.pack(padx=5, side=LEFT) button3 = Button(framedesign, text='Thanks', width=5, height=4, command = Thanks, activebackground = 'Cyan') button3.pack(side=LEFT) code.master.title("Advance iconbitmap usage Example with different text on buttons") code.pack(fill=BOTH) code.pack() app = Icon() program.mainloop()

 Output:

When Code is Executed

When “Thanks” Button is Pressed

Window

3. tk.call() Method

This method is an interface of Tkinter to the tcl interpreter. Image used in example [i] & example [ii]-

[i] Basic tk.call() Usage Example

This example represents the use of chúng tôi method.

Code:

import tkinter as tk program = tk.Tk() program.title('tk.call() method basic example') program.tk.call('wm', 'iconphoto', program._w, tk.PhotoImage(file='C:/Users/afu/Desktop/tk/dino.png')) program.mainloop()

Output:

 [ii] Advance tk.call() Usage Example

Code:

import tkinter as tk from tkinter import Tk from tkinter import Frame from tkinter import Label from tkinter import SUNKEN, LEFT from tkinter import FLAT, BOTH from tkinter import RIDGE, RAISED from tkinter import GROOVE program = tk.Tk() program.tk.call('wm', 'iconphoto', program._w, tk.PhotoImage(file='C:/Users/afu/Desktop/tk/dino.png')) class Icon(Frame): def __init__(code): super().__init__() code.UI() def UI(code): code.master.title("Advance tk.call() usage example") code.pack(fill=BOTH) framedesign = Frame(code, borderwidth=10) framedesign.pack() label1 = Label(framedesign, width=20, bg='#02FAFE', height=15, relief=GROOVE) label1.pack(padx=5, side=LEFT) label2 = Label(framedesign, bd=4, bg='#16DFE2', width=10,height=15, relief=GROOVE) label2.pack(padx = 5, side=LEFT) label3 = Label(framedesign, bd=4, bg='#28A6A8', width=20,height=15, relief=FLAT) label3.pack(padx=5,side=LEFT) label4 = Label(framedesign, bd=2, bg='#2A7778', width=10, height=15, relief=RAISED) label4.pack(padx = 5, side=LEFT) label5 = Label(framedesign, bd=3, bg='#173232', width=20, height=15, relief=RIDGE) label5.pack(padx=5,side=LEFT) code.pack() app = Icon() program.mainloop()

Output:

Conclusion

On the basis of the above example, an individual can understand how to set up images as a window’s icon. The different methods and examples describe the process of setting up images as an icon in different ways and also briefly introduce the different aspects of creating a GUI using Tkinter.

Recommended Articles

We hope that this EDUCBA information on “Tkinter Icon” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Update the detailed information about Syntax And Different Examples Of Jquery Innerwidth() on the Bellydancehcm.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!