Tkinter Python Program Examples

Posted By admin On 07.09.19
Tkinter Python Program Examples 3,5/5 8796 reviews
  1. Python Tkinter Script Example
  2. Python Tkinter Gui Examples
Active14 days ago

Python Tkinter.Entry Examples The following are code examples for showing how to use Tkinter.Entry. They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account. This call (say, for example, creating a button widget), is implemented in the Tkinter module, which is written in Python. This Python function will parse the commands and the arguments and convert them into a form that makes them look as if they had come from a Tk script instead of a Python script. Python GUI Programming (Tkinter) – Part I In this Python GUI programming tutorial you will learn about how to make GUI programs using Python Tkinter toolkit. Graphical User Interface, also known as GUI is one of the best features in programming that makes a program look visually more attractive than the normal text based programs covered with.

I am writing a program which should:

  1. Open a window with the press of a button.
  2. Close the newly opened window with the press of another button.

I'm using classes so I can insert the code into a larger program later. However, I can't get my buttons to load correctly.

Stevoisiak
7,22912 gold badges53 silver badges113 bronze badges
ADBADB
4953 gold badges7 silver badges21 bronze badges

5 Answers

I rewrote your code in a more organized, better-practiced way:

Result:

Stevoisiak
7,22912 gold badges53 silver badges113 bronze badges
Rushy PanchalRushy Panchal
9,55211 gold badges45 silver badges77 bronze badges

You need to specify the master for the second button. Otherwise it will get packed onto the first window. This is needed not only for Button, but also for other widgets and non-gui objects such as StringVar.

Quick fix: add the frame new as the first argument to your Button in Demo2.

Possibly better: Currently you have Demo2 inheriting from tk.Frame but I think this makes more sense if you change Demo2 to be something like this,

Just as a suggestion, you should only import tkinter once. Pick one of your first two import statements. Drivers inland ma3303 sound.

JaredJared
16.4k7 gold badges41 silver badges58 bronze badges
Halvor Holsten Strand
16.3k15 gold badges58 silver badges74 bronze badges
SumantaSumanta

What you could do is copy the code from tkinter.py into a file called mytkinter.py, then do this code:

And you have two windows which don't collide!

WhyAreYouReadingThisWhyAreYouReadingThis

I tried to use more than two windows using the Rushy Panchal example above. The intent was to have the change to call more windows with different widgets in them. The butnew function creates different buttons to open different windows. You pass as argument the name of the class containing the window (the second argument is nt necessary, I put it there just to test a possible use. It could be interesting to inherit from another window the widgets in common.

Giovanni PythonGiovanni Python
8,3851 gold badge19 silver badges28 bronze badges

Python Tkinter Script Example

Not the answer you're looking for? Browse other questions tagged pythonclasstkinterdestroy or ask your own question.

Python tkinter tutorials

GUI Tk /

Alarm1Animation3
Back Fore ground1Beeper1
Border7Button32
Canvas8CheckBox7
Common Dialog9Cursor1
Dialog14Editor1
Event9Exception Dialog1
Focus1Frame23
Label16Layout40
LED1ListBox7
Menu Checkbox1Menu RadioButton1
Menu18MenuButton1
Message Box1OptionMenu1
Pack4Popup Menu1
RadioButton9Scale8
ScrollBar2StatusBar MessageField2
Table Grid5Text11
TextArea4TextField Entry12
Timer2Tk option database1
TK Root Window3ToolBar2
Top Level1UI Class15
UI Event1

Event /

Key Action15Mouse Action23
Mouse Draw3

GUI Pmw /

Pmw AboutDialog2Pmw Blt Tabset1
Pmw Border1Pmw ButtonBox5
Pmw Color2Pmw ComboBox7
Pmw ComboBoxDialog2Pmw Counter9
Pmw CounterDialog2Pmw Dialog8
Pmw EntryField15Pmw Error Handler2
Pmw Gauge1Pmw Grid2
Pmw Group8Pmw HistoryText1
Pmw Key Action1Pmw LabeledWidget2
Pmw LogicalFont1Pmw MegaWidget4
Pmw MenuBar2Pmw MessageBar2
Pmw MessageDialog7Pmw Multi line label2
Pmw OptionMenu4Pmw Password1
Pmw Performance1Pmw PromptDialog1
Pmw RadioSelect5Pmw ScrolledCanvas4
Pmw ScrolledField1Pmw ScrolledFrame1
Pmw ScrolledListBox5Pmw ScrolledText4
Pmw SelectionDialog2Pmw Splitpane3
Pmw StatusBar1Pmw Tab NoteBook4
Pmw TextDialog2Pmw TimeCounter2
Pmw Tooltips2Pmw Toplevel Megawidget1
Pmw Validation Field9Subclassing Pmw3

2D /

Arc2Bitmap2
Circle1Color2
Curve1Font7
Gif1Image1
Line5Oval3
Polygon1Rectangle2
Shape Border2

List /

List Append4List Assign5
List Cancatenation5List Compare3
List Comprehensive6List Count1
List Declaration1List Element Insert1
List Element Remove1List Element Replace1
List Element4List Empty1
List Extend3List Filter1
List In3List Index2
List Indexing7List Insert2
List Intersect2List Length2
List Loop6List Pop3
List Remove5List Repitition1
List Reverse2List Sliced7
List Sort3List Two Dimension2
Nested List3Return List1
Variables in List1

Tuple /

Nested Tuple1Tuple Concatination2
Tuple Condition1Tuple Creation6
Tuple Declaration4Tuple Display1
Tuple Element1Tuple Immutable1
Tuple In3Tuple Index4
Tuple Length2Tuple Loop3
Tuple Range1Tuple Repitition1
Tuple Returned1Tuple Slice2
Tuple toList2Tuple Zip1

Dictionary /

Dictionary Assignment4Dictionary Clear1
Dictionary Copy3Dictionary Declaration3
Dictionary Del1Dictionary Fetch1
Dictionary get3Dictionary has Key4
Dictionary items2Dictionary iteritems1
Dictionary Key6Dictionary List1
Dictionary Loop3Dictionary Output1
Dictionary popitem1Dictionary Print1
Dictionary setdefault1Dictionary Tuple3
Dictionary update2Dictionary values2

String /

Append1Format1
Loop2String Case2
String Cast5String center1
String Compare1String Concatenation3
String count1String cross Line1
String Declaration3String Ends1
String endsWith1String Escape4
String find2String In3
String Index4String join6
String Length6String ljust1
String Output2String Quotation3
String R1String Repitition2
String Replace5String rfind1
String rindex1String rjust1
String Slice6String Special Char1
String Split4String startsWith1
String strip1String toTitle1
String Variables2zfill1

Class /

Class abstract1Class add1
Class call1Class Constructor5
Class Define2Class Definition8
Class del1Class Dict2
Class fields10Class getattr2
Class getitem2Class getslice1
Class Inheritance12Class Instance1
Class instantiation1Class iter1
Class len1Class list1
Class metaclass1Class Method5
Class mul1Class Operator Add1
Class Private1Class radd1
Class repr1Class self1
Class setattr1Class str3
Class sub1Class Virtual6
Static1

Function /

Apply2Function as Parameters3
Function as Return2Function Default Argument10
Function Define7Function Dictionary Parameters4
Function Inner4Function Keyword Arguments3
Function Parameters5Function Recursive3
Function Return5Function Tuple Parameters6
Function type vars1Functional Programming5
lambda function5Return3

Buildin Function /

chr1Del1
dict1Dir3
enumerate1Eval1
filter4Float Function1
Generator Function3Generator3
id1in3
int cast2Iterable Object1
Iterator Behavior1Iterators1
len3list4
map6next2
ord2range8
reduce4repr6
reversed1sorted1
str4zfill1
zip7

Data Type /

Array1Bigger Number1
Bit3Boolean3
Complex Numbers6Decimal1
Float2Hex Function1
Hex Type1Int11
Long1maxint2
Oct Function1octal Type1
True2Type Conversion2

Data Structure /

bisect1Deque1
Queue1Set Declaration2
Set In1Set3
Stack2

Database /

DBM3MySQL3
ODBC1Pickle5
shelve3

File /

Dircetories4File Binary1
File Close3File IO Exception1
File Object1File Open1
File Pointer1File Read9
File Readline3File seek2
File Tell1File Text2
File Utilities1File Utility2
File Write6File Zip4
IO Error3Text File Read Write2
Text File Read8Text File Write4

Development /

Command Line3Compress1
Console Read4Date Time6
Doc String6Encode File2
Environment2Help2
isinstance1Logging1
Output Format25Path1
Random10Reflection1
Standard Read5Standard Redirect5
Standard Vars1stdout stderr6
Test1Timer1
User Input2

Language Basics /

And Or7Break4
Buildin Error2Catch Exceptions3
Comments3Continue3
def1Divide4
For In2For5
Garbage Collector1Global5
If10Import3
Local Variables2Locale1
Logical Operator1Module15
Multiply3Not1
Operator1Pass1
Plus1pprint1
Print3Raise1
Statement1Static Method2
Subtract1Text Encode3
Try Else2Try finally1
Try2Type2
Unicode9Variable Assign3
Variable Declaration2Variable Immutable2
Variable Reference1While12

Exception /

Python Tkinter Gui Examples

Exception Class3Exception finally1
Exception Handle6Exception Info3
Exception Raise2Exception Trace1
Exception Type1Value Error1

Math /

cos1E1
Log1Math Pow1
Max2Min2
Mod1Pi1
Power2Round2
Sin2sqrt1

Network /

Address Info3CGI5
Email8FTP4
Gopher Client5Host Info3
HTML Parser2HTTP POST1
Internet Access1IP Address1
Proxy1Remote File1
Server UDP2Socket Broadcast1
Socket Client3Socket Error Handle3
Socket Info1Socket Option1
Socket Pocket2Socket Server6
TCP5UDP4
URL7Web Client6
Web Page3Web Server1

Thread /

Thread Exit1Thread Sleep1
Thread Start1Thread Synchronize3

System /

System Cmd Mount3System Command1
System Error1System Exit1
System fork1System Info1
System Path4System pid1
System Time1System User1
System Variables3

XML /

Handler2SAX4
XML Children Node5XML Element4
XML Parse7XML Transform3

Utility /

API Helper2Command Line1
Command2Exception1
File Utility16Network Utility7
Programming21Regular Expressions1

Application /

Calculator2