FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PySimpleGUI/DemoPrograms/Demo_Drag_and_Drop.py at master · PySimpleGUI/PySimpleGUI · GitHub
PySimpleGUI
/
PySimpleGUI
Public
Notifications
You must be signed in to change notification settings
Fork
1.8k
Star
13.8k
Code
Issues
708
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
PySimpleGUI
/
DemoPrograms
/
Demo_Drag_and_Drop.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (39 loc) · 1.83 KB
Breadcrumbs
PySimpleGUI
/
DemoPrograms
/
Demo_Drag_and_Drop.py
Copy path
File metadata and controls
52 lines (39 loc) · 1.83 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
46
47
48
49
50
51
52
import
psgdnd
as
dnd
import
PySimpleGUI
as
sg
"""
Demo - Drag and Drop using tkinterdnd2
Experimental drag and drop demo using tkinterdnd2 (you'll need to pip install it)
python -m pip install tkinterdnd2
Routes drop event through the window.read.
Usage:
* Register elements for drop events
register_element_dnd(element, window, drop_type)
* In event loop - drop events signaled via DropEvent object and value in values dict
DropEvent object has fields:
key
element
drop_type
window
values[event] = filename(s) or text that was dropped as a string
Copyright 2026 PySimpleGUI. All rights reserved.
"""
def
main
():
layout
=
[[
sg
.
Text
(
'Filename to process'
)],
[
sg
.
Input
(
key
=
"-INPUT-"
,
expand_x
=
True
),
sg
.
FileBrowse
(
'Browse'
)],
[
sg
.
Button
(
"OK"
),
sg
.
Button
(
"Cancel"
)]]
# layout = [[sg.Column(layout, p=0, k='-COL-', expand_y=True, expand_x=True)]] # if want to make the entire window the target
window
=
sg
.
Window
(
"File Drop Example"
,
layout
,
finalize
=
True
,
auto_save_location
=
True
,
resizable
=
True
)
# register all elements to receive drop events
for
key
,
element
in
window
.
key_dict
.
items
():
dnd
.
register_element_dnd
(
element
,
window
,
dnd
.
DROP_TYPE_FILES
)
while
True
:
event
,
values
=
window
.
read
()
# print(event, values)
if
event
in
(
sg
.
WIN_CLOSED
,
"Cancel"
):
break
if
dnd
.
is_drop_event
(
event
):
# if it's a drag and drop event
if
event
.
key
==
'-INPUT-'
:
# see what element was dropped on
window
[
'-INPUT-'
].
update
(
values
[
event
])
# update the Input Element with text from event
window
.
close
()
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL