FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
code-guild/code-guild/python/tkinter/basic_window.py at master · grantholly/code-guild · GitHub
grantholly
code-guild
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
code-guild
/
code-guild
/
python
/
tkinter
/
basic_window.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (40 loc) · 1.41 KB
Breadcrumbs
code-guild
/
code-guild
/
python
/
tkinter
/
basic_window.py
Copy path
File metadata and controls
47 lines (40 loc) · 1.41 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from
Tkinter
import
Tk
,
BOTH
from
ttk
import
Frame
,
Button
,
Style
class
Example
(
Frame
):
def
__init__
(
self
,
parent
):
Frame
.
__init__
(
self
,
parent
)
self
.
parent
=
parent
self
.
initUI
()
self
.
center_window
()
def
center_window
(
self
):
width
=
290
height
=
150
# figure out the device screen size
screen_width
=
self
.
parent
.
winfo_screenwidth
()
screen_height
=
self
.
parent
.
winfo_screenheight
()
# calculate the midpoints
x
=
(
screen_width
-
width
)
/
2
y
=
(
screen_height
-
height
)
/
2
# set the window in a centered fashion
self
.
parent
.
geometry
(
"%dx%d+%d+%d"
%
(
width
,
height
,
x
,
y
))
def
initUI
(
self
):
self
.
parent
.
title
(
"window"
)
self
.
pack
(
fill
=
BOTH
,
expand
=
1
)
self
.
style
=
Style
()
# use hte OS theme for the window
self
.
style
.
theme_use
(
"default"
)
# add quit button instance
quit_button
=
Button
(
self
,
text
=
"quit here"
,
command
=
self
.
quit
)
# position button absolutely in window
quit_button
.
place
(
x
=
100
,
y
=
100
)
def
main
():
root
=
Tk
()
root
.
geometry
(
"300x300+100+100"
)
# create an instance of our window
app
=
Example
(
root
)
# the main loop is running in the background
# this will listen for events inside the window
# this will also dispatch event handers
root
.
mainloop
()
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL