Trending December 2023 # Guide To C# Directoryinfo With Properties, Methods # Suggested January 2024 # Top 12 Popular

You are reading the article Guide To C# Directoryinfo With Properties, Methods updated in December 2023 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 January 2024 Guide To C# Directoryinfo With Properties, Methods

Introduction to C# DirectoryInfo

Web development, programming languages, Software testing & others

Syntax

Below is the simple syntax for the implementation of the DirectoryInfo class. We can explain the below syntax in the following ways.

First, we have defined a class with a variable with a type of DirectoryInfo.

We are assigning the object created by DirectoryInfo with help of a new keyword.

We can see the syntax here we are passing the dpath for the object creation to the DirectoryInfo class.

Here dpath is any string of path.

Finally, we are using the code as the directory.create, and it will create the directory.

Remember that we should also check for whether a directory already exists or not.

DirectoryInfo directory = new DirectoryInfo(dPath); directory.Create(); Working of C# DirectoryInfo class

We can explain the working of the DirectoryInfo class in the following way.

Namespace chúng tôi contains the class the DirectoryInfo, so if we want to use it we need to include this library.

Most important thing about it, by using the available command we can create and move the directory.

It has many methods which are the key strength of the DirectoryInfo, which allows us to perform creation and deletion.

Most important point about the DirectoryInfo class is that we cannot inherit it because it is a sealed class (we can learn more about the sealed class in C# in its documentation).

Constructors of C# DirectoryInfo

In the constructors are the way to initialization of the DirectoryInfo class. Here we need to pass the path to initialize, and the path is the string of directory which we want to create or move.

Function type ( private/public/protected ) DirectoryInfo ( string directoryPath );

Attribut,

Methods of C# DirectoryInfo

Here are the following methods mention below:

Create ( string ): If we want to create a new directory we can use the method. Here in the method, we are passing a string which string path for which we want to create the directory.

CreateSubdirectory: We learned that we can create the directory with the help of the method create, now what if we wanted to create a directory inside another directory ( subdirectory ). We can simply use the CreateSubdirectory method for it. Bypassing a string path to this method we can also create a subdirectory to the specified path.

MoveTo: It used to move all the constants and the instances of the directory to the other location.

Delete: It will delete the specified directory, bypassing a boolean value to it we can inform its compiler if we want to delete its subdirectory also.

GetDirectories: To know about the subdirectory we can use this method. Many times in real life programming where we need to know the pathname before deleting, so it will be very useful as it mentions the subdirectory details.

GetFiles: In case if we want to get the file from the specified directory then we can use the GetFile method.

GetType(): To know the type of instance ( current ).

Refresh(): To refresh the object state we can use the method Refresh().

SetAccessControl: This method is mostly used for security reasons and it will get a DirectorySecurity as the object to describe it.

ToString(): To get the original path that was passed by the user we can use the method ToString().

Properties of C# DirectoryInfo

Here are the properties mention below

CreationTime: In case if we wanted to know the date and time of the directory creation then we can use the property CreationTime.

Exists: It returns the boolean value, which shows if the directory exists or not. In case if the directory is already there then it returns true ele it will return false.

FullName: If we wanted to get the full name of the file ( which means starting from root directory ).

Name: In this case, it used simply to get the name of the directory.

LastAccessTime: In case if we wanted to get the last date and time when the directory was modified then we can use this property.

LastWriteTime: If we wanted to get the last file changes and save the details of the changes.

Extension: It is used to get the string representing the extension part of the file.

Parent: In case if we wanted to get the parent directory name then we can use Parent. It will give us the parent directory name.

Example of C# DirectoryInfo

Below is a very simple example, here we are simply trying to create a directory, we are also checking if the directory already exists or not.

Code:

using System.IO; using System; class createDirectory { static void Main() { string dPath = @"D:directoryExample"; DirectoryInfo directory = new DirectoryInfo(dPath); if (directory.Exists) { Console.WriteLine("The directory which you are trying to create is already there"); } else { directory.Create(); Console.WriteLine("Congratulation we have created directory"); } Console.ReadLine(); } }

Output:

Conclusion

From this tutorial, we learned about the DirectoryInfo in C# and we learned about the DirectoryInfo behaviors with a very important example. We learned about the constructors and methods of the DirectoryInfo. We understand the working of DirectoryInfo in C#.

Recommended Articles

This is a guide to C# DirectoryInfo. Here we discuss the working, constructors, properties, methods of C# DirectoryInfo with example for better understanding. You may also have a look at the following articles to learn more –

You're reading Guide To C# Directoryinfo With Properties, Methods

C++ Program To Find Matrix With Marked Asterisks Region

Suppose we have a n x n grid of characters with dots (.) and asterisks (*). All cells are marked as dot except two cells. We have to mark two more cells so that they are the corners of a rectangle with sides parallel to the coordinate axes. If there are multiple solutions available, return any one of them.

Problem Category

An array in the data structure is a finite collection of elements of a specific type. Arrays are used to store elements of the same type in consecutive memory locations. An array is assigned a particular name and it is referenced through that name in various programming languages. To access the elements of an array, indexing is required. We use the terminology ‘name[i]’ to access a particular element residing in position ‘i’ in the array ‘name’. Various data structures such as stacks, queues, heaps, priority queues can be implemented using arrays. Operations on arrays include insertion, deletion, updating, traversal, searching, and sorting operations. Visit x1 := -1, x2 := -1, y1 = -1, y2 = -1 for initialize i := 0, when i < n, update (increase i by 1), do:    for initialize j := 0, when j < n, update (increase j by 1), do:       if M[i, j] is same as ‘*’ and x1 is same as -1, then:          x1 := i, y1 := j       if M[i, j] is same as ‘*’ and x1 is not equal to -1, then:          x2 := i, y2 := j if x1 is same as x2, then:    if x1 is not equal to n – 1, then:       M[x1 + 1, y1] = M[x2 + 1, y2] = ‘*’    Otherwise       M[x1 – 1, y1] = M[x2 – 1, y2] = ‘*’ otherwise when y1 is same as y2, then:    if y1 is not equal to n – 1, then:       M[x1, y1 + 1] = M[x2, y2 + 1] = ‘*’    Otherwise       M[x1, y1 – 1] = M[x2, y2 – 1] = ‘*’ Otherwise    M[x1, y2] := M[x2, y1] = ‘*’ for initialize i := 0, when i < n, update (increase i by 1), do:    for initialize j := 0, when j < n, update (increase j by 1), do:       print M[i, j] using namespace std;    int i, j, x1, y1, x2, y2;    int n = M.size();    x1 = x2 = y1 = y2 = -1;    for (i = 0; i < n; i++){       for (j = 0; j < n; j++){          if (M[i][j] == ‘*’ && x1 == -1)             x1 = i, y1 = j;          if (M[i][j] == ‘*’ && x1 != -1)             x2 = i, y2 = j;       }    }    if (x1 == x2){       if (x1 != n – 1)          M[x1 + 1][y1] = M[x2 + 1][y2] = ‘*’;       else          M[x1 – 1][y1] = M[x2 – 1][y2] = ‘*’;    }    else if (y1 == y2){       if (y1 != n – 1)          M[x1][y1 + 1] = M[x2][y2 + 1] = ‘*’;       else          M[x1][y1 – 1] = M[x2][y2 – 1] = ‘*’;    }    else       M[x1][y2] = M[x2][y1] = ‘*’;    for (i = 0; i < n; i++){       for (j = 0; j < n; j++)          printf(“%c”, M[i][j]);       printf(“n”);    } } int main(){       { ‘*’, ‘.’, ‘.’, ‘.’ }, { ‘.’, ‘.’, ‘.’, ‘.’ } };    solve(matrix); }

Input { { '.', '.', '*', '.' }, { '.', '.', '.', '.' },    { '*', '.', '.', '.' }, { '.', '.', '.', '.' } } Output *.*. .... *.*. ....

C++ Program To Implement Hash Tables With Quadratic Probing

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched. Quadratic probing is a collision resolving technique in Open Addressed Hash tables. It operates by taking the original hash index and adding successive values of an arbitrary quadratic polynomial until an open slot is found.

This is a C++ program to Implement Hash Tables with Quadratic Probing.

Algorithm

For search a key value:

Begin    Declare function SearchKey(int k, HashTable *ht)       intialize collisions = 0          pos = pos + 2 * ++collisions -1       return pos End.

For Insert:

Begin    Declare function Insert(int k, HashTable *ht)       int pos = SearchKey(k, ht) End.

For Display:

Begin    Declare function display(HashTable *ht)          if (!value)             print"Position: "                print the current position             Print" Element: Null"          else             print"Position: "                print the current position             Print" Element: "                Print the element. End.

For Rehash Function:

Begin    Declare function Rehash(HashTable *ht)       ht= initiateTable(2 * s)       for (int i = 0; i < s; i++)          if (t[i].info == Legi)             Insert(t[i].e, ht)       free(t)       return ht End. #define T_S 10 using namespace std; enum EntryType {    Legi, Emp, Del};    struct HashTableEntry {       int e;       enum EntryType info;    };    struct HashTable {       int s;       HashTableEntry *t;    };    bool isPrime (int n) {       return true;       return false;    for (int i = 3; i * i <= n; i += 2)       if (n % i == 0)          return false;    return true; } int nextPrime(int n) {    if (n <= 0)       n == 3;    if (n % 2 == 0)       n++;    for (; !isPrime( n ); n += 2);       return n; } int HashFunc(int k, int s) {    return k % s; } HashTable *initiateTable(int s) {    HashTable *ht;    if (s < T_S) {       cout<<"Table Size is Too Small"<<endl;       return NULL;    }    ht= new HashTable;    if (ht == NULL) {       cout<<"Out of Space"<<endl;       return NULL;    }       cout<<"Table Size is Too Small"<<endl;       return NULL;    }    }    return ht; } int SearchKey(int k, HashTable *ht) {    int collisions = 0;       pos = pos + 2 * ++collisions -1;    }    return pos; } void Insert(int k, HashTable *ht) {    int pos = SearchKey(k, ht);    } } HashTable *Rehash(HashTable *ht) {    ht= initiateTable(2 * s);    for (int i = 0; i < s; i++) {       if (t[i].info == Legi)          Insert(t[i].e, ht);    }    free(t);    return ht; } void display(HashTable *ht) {       if (!value)          cout<<"Position: "<<i + 1<<" Element: Null"<<endl;       else          cout<<"Position: "<<i + 1<<" Element: "<<value<<endl;    } } int main() {    int v, s, pos, i = 1;    int c;    HashTable *ht;    while(1) {       cout<<"1.Initialize size of the table"<<endl;       cout<<"2.Insert element into the table"<<endl;       cout<<"3.Display Hash Table"<<endl;       cout<<"4.Rehash The Table"<<endl;       cout<<"5.Exit"<<endl;       cout<<"Enter your choice: ";       switch(c) {          case 1:             cout<<"Enter size of the Hash Table: ";             ht = initiateTable(s);             cout<<"Size of Hash Table: "<<nextPrime(s);          break;          case 2:                cout<<"Table is Full, Rehash the table"<<endl;                continue;             }             cout<<"Enter element to be inserted: ";             Insert(v, ht);             i++;          break;          case 3:             display(ht);          break;          case 4:             ht = Rehash(ht);          break;          case 5:             exit(1);          default:             cout<<"nEnter correct optionn";       }    }    return 0; } Output 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 1 Enter size of the Hash Table: 4 Table Size is Too Small Size of Hash Table: 51.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 1 Enter size of the Hash Table: 10 Size of Hash Table: 111.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Enter element to be inserted: 1 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Enter element to be inserted: 2 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Enter element to be inserted: 3 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Enter element to be inserted: 4 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Enter element to be inserted: 5 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Enter element to be inserted: 6 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Enter element to be inserted: 7 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Enter element to be inserted: 8 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Enter element to be inserted: 9 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Enter element to be inserted: 10 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Enter element to be inserted: 11 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Table is Full, Rehash the table 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 3 Position: 1 Element: 11 Position: 2 Element: 1 Position: 3 Element: 2 Position: 4 Element: 3 Position: 5 Element: 4 Position: 6 Element: 5 Position: 7 Element: 6 Position: 8 Element: 7 Position: 9 Element: 8 Position: 10 Element: 9 Position: 11 Element: 10 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 4 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 3 Position: 1 Element: Null Position: 2 Element: 1 Position: 3 Element: 2 Position: 4 Element: 3 Position: 5 Element: 4 Position: 6 Element: 5 Position: 7 Element: 6 Position: 8 Element: 7 Position: 9 Element: 8 Position: 10 Element: 9 Position: 11 Element: 10 Position: 12 Element: 11 Position: 13 Element: Null Position: 14 Element: Null Position: 15 Element: Null Position: 16 Element: Null Position: 17 Element: Null Position: 18 Element: Null Position: 19 Element: Null Position: 20 Element: Null Position: 21 Element: Null Position: 22 Element: Null Position: 23 Element: Null 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 2 Enter element to be inserted: 20 1.Initialize size of the table 2.Insert element into the table 3.Display Hash Table 4.Rehash The Table 5.Exit Enter your choice: 5

Constructors And Methods With Example In Jeditorpane

Introduction to JEditorPane

Web development, programming languages, Software testing & others

In order to have this behavior, this component uses the implementations of the EditorKit. The beauty is that it automatically adjusts to the proper kind of text editor for whichever kind of content it is provided. The EditorKit which is currently installed is used to determine the content that the editor is bound to at any given time. For example, if the content of a component is set to a new URL, then its type is used to determine the EditorKit that should be preinstalled to load the content.

Syntax:

public class JEditorPane extends JTextComponent

By Default this class is preconfigured to the following three types of content:

text/plain: Plain Text, which is the default type when the content is not recognized. The kit used over here is an extension of DefaultEditorKit that will produce a wrapped plain text view.

text/HTML: HTML Text. The kit used over here is class javax.swing.text.html.HTMLEditorkit which will provide support till HTML (ver. 3.2).

text/RTF: RTF Text. The kit used over here is class javax.swing.text.rtf.RTFEditorkit which will provide limited support Rich Text Format.

Constructors of JEditorPane

Below are the constructors of JEditorPane:

JEditorPane( ): This type of constructor will simply create a new JEditorPane.

JEditorPane(String URL): This type of constructor will create a JEditorPane based on the string in the parameter containing the URL specifications.

JEditorPane(URL initial page): This constructor will create the JEditorPane based on the specified URL in the input parameter.

JEditorPane( String type, String text ): This constructor will create a JEditorPane that has been initialized to the text given within the parameter.

Some Useful Methods of JEditoPane Class

void setText(String text): This method will set the text of the component with the specified text given in the input, which is expected to be in the same content type as of the editor.

Void getText( ): This method will return the text of the component within the specified content type of the editor.

Void setPage(URL page): This method will trigger the JEditorPane to show the specified URL as the current page.

Void setContentType(String type): This method is used to set the type of content that the editor can handle.

Example of JEditorPane Class

Below are the examples of JEditorPane:

Here in this example, we will create a web page reader using JEditorPane in java. We can’t also consider it as a web browser since JEditorPane can only use to show HTML content and it cant show any CSS or any other styling content but still some webpages with there HTML content can be accessed via the example as well as we also open any HTML file which saved on the local PC.

Over here in order to build a web page viewer, we will first create an editor pane to show the HTML content then create a JTextfield which will be used to fill the URL and a JButton which is used to search the URL on the web. Add an action to the button and hyperlink listener which can be used for any hyperlink on the HTML page. In the end, add all the components to the panel and the panel to the frameset the size of the frame and also make the webpage as read-only so that no changes can be made using the setEditable method as False.

import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import java.net.URL; import javax.swing.JButton; import javax.swing.event.HyperlinkEvent;// Provides information on events triggered import javax.swing.event.HyperlinkListener;// Monitors user activity with links public class JEditorPaneExample extends JFrame implements HyperlinkListener, ActionListener { public static void main(String[] args) { } String defaultURL; JPanel panel = new JPanel(); JTextField theURL = new JTextField(25); JButton search = new JButton("Search"); JEditorPane htmlPage; public JEditorPaneExample(String defaultURL) { JFrame frame = new JFrame("Java Browser"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.defaultURL = defaultURL; search.addActionListener(this); theURL.setText(defaultURL); panel.add(theURL); panel.add(search); frame.add(panel, BorderLayout.NORTH); try { htmlPage = new JEditorPane(defaultURL); htmlPage.addHyperlinkListener(this); htmlPage.setEditable(false); JScrollPane scroller = new JScrollPane(htmlPage); frame.add(scroller, BorderLayout.CENTER); } catch (IOException e) { e.printStackTrace(); } frame.setSize(1200, 800); frame.setVisible(true); } public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { htmlPage.setPage(e.getURL()); theURL.setText(e.getURL().toExternalForm()); } catch (IOException e1) { e1.printStackTrace(); } } } public void actionPerformed(ActionEvent e) { String pageURL = ""; if (e.getSource() == search) { pageURL = theURL.getText(); } else { pageURL = defaultURL; JOptionPane.showMessageDialog(JEditorPaneExample.this, "Please Enter a Web Address", "Error", JOptionPane.ERROR_MESSAGE); } try { htmlPage.setPage(new URL(pageURL)); theURL.setText(pageURL); } catch (MalformedURLException e2) { JOptionPane.showMessageDialog(JEditorPaneExample.this, JOptionPane.ERROR_MESSAGE); } catch (IOException e1) { e1.printStackTrace(); } } }

Output:

Conclusion

JEditorPane class can be used to display normal HTML, Rich Text Format Content or Plain text with a bit of styling. The JEditorPane class provides an edge over JTextPanes for providing text component as the JEditorPane class provides you constructors to initialize the editor pane form a URL whereas JTextPane doesn’t have such contractors.

Recommended Articles

This is a guide to JEditorPane. Here we discuss constructors, methods, and examples in JEditorPane. You can also go through our other related 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.

How Quicksort Work In C++ With Algorithm

Introduction to C++ QuickSort

The following article provides an outline for C++ QuickSort. In programming language we always need algorithm to make it efficient and quicksort is one of them. As the name suggest it is used to sort the elements. It follows some steps to do this. This algorithm select one element from the list which is known as ‘pivot’ and it turns divide the list two parts for effective sorting.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax of C++ QuickSort

As it is an algorithm so it does not have syntax with it but it defines some step which need to be followed while implementing quick sort in any language.

Step A: Pick one element from list as pivot.

Step B: Pick two element as left and right.

Step C: Left element represent low index.

Step D: Right element represent high index.

Step E: If value at left is less move right.

Step F: If value at right is more move left.

We will perform this steps until the smaller and greater elements passes each other.

How QuickSort work in C++ with Algorithm

As now we know that QuickSort is used to sort the element in an efficient way. It is an algorithm which define some steps to follow in order to implement this in code. This algorithm basically work with pivot element, it takes one element from list as pivot and divide the whole list into two sub list and sort them.

We can choose the pivot element in different ways which are defined below:

We can take last element as the pivot element.

We can take middle element as the pivot element.

We can take first element as the pivot element.

We can take any random element as the pivot element.

We can follow any of the approaches which will turn divide our list of element into two different sub list further. We will move the other elements into the array or list to left and right in order to sort.

Below we can see one simple algorithm which is used to define the QuickSort in C++ language.

Algorithm:

quickSorAlgo(Array, less, more)

//starting algo logic

begin

Here we are defining an array which needs to be sorted

less = first element;

more = last element;

pivot

if(less < more)

//starting sorting logic

begin

quickSorAlgo(Array,less,pivot-1)

quickSorAlgo(Array,pivot+1,more)

//here it ends

End

//algo ends

end

Let’s understand the algorithm in detail:

50, 25, 15, 20, 60, 30.

Consider the above array which contains various element inside it. We are selecting here pivot element as the last element, and accordingly we have marked first element of array as low and last element of array as high. Now we will iterate our pointers to the respective positions, but for this we will follow one rule to compare the elements.

If marked element high is smaller than our selected pivot element and low marked element is greater than our pivot element in this case we will exchange the potions of the element with each other and we are going to increment the positions of our respective elements as well where they should point to. We are going to continue this iteration until our low and high element cross each other and the pivot element is in the proper position where it should be, this will portioned the array or list into two sub list, this two list can be sorted with QuickSort algorithm independently.

So the final output from the above sorting algorithm would be this. We can easily and effectively sort our arrays by using QuickSort algorithm in C++.

Points to remember while working with QuickSort:

First we need to select the pivot elements from the array, it can be anything like, first, last, random or middle elements from the array of elements.

It has different complexity which are mentioned below:

Worst case: O (n 2 )

Average case: O (n log n)

Best case: O (n log n)

By the use of it we can sort our array elements faster which improves the performance as well.

Example of C++ QuickSort

In this example we are sorting array elements using quick sort an considering the pivot element as the last element from the array.

Code:

using namespace std; void elementSwap(int* ele1, int* ele2) { int temp = *ele1; *ele1 = *ele2; *ele2 = temp; } int elementPartition (int array[], int less, int more) { int pivotelement = array[more]; int indexSmaller = (less – 1); for (int qs = less; qs <= more – 1; qs++) { if (array[qs] < pivotelement) { indexSmaller++; elementSwap(&array[indexSmaller], &array[qs]); } } elementSwap(&array[indexSmaller + 1], &array[more]); return (indexSmaller + 1); } void demoquickSort(int array[], int less, int greater) { if (less < greater) { int parInd = elementPartition(array, less, greater); demoquickSort(array, less, parInd – 1); demoquickSort(array, parInd + 1, greater); } } int main() { cout << “Sorting array elemnts using quick sort in C++ ::** n”; int array[] = {35, 15, 90, 26, 87, 12, 5, 44, 23, 1}; int arrsize = sizeof(array) / sizeof(array[0]); cout << “Before sort array is : n”; int z; for (z = 0; z < arrsize; z++) cout << array[z] << ” “; cout << endl; demoquickSort(array, 0, arrsize – 1); cout << “After sorted array is : n”; int i; for (i = 0; i < arrsize; i++) cout << array[i] << ” “; cout << endl; return 0; }

Output:

Conclusion

By using QuickSort algorithm we can efficiently sort our array list elements. We just need to select the pivot element in order to proceed with it. This will divide the array or list into two parts then we can perform QuickSort algorithm recursively in order to get the sorted elements list.

Recommended Articles

This is a guide to C++ QuickSort. Here we discuss the introduction, how QuickSort work in C++ with algorithm and example respectively. You may also have a look at the following articles to learn more –

Update the detailed information about Guide To C# Directoryinfo With Properties, Methods 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!