-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.html
214 lines (189 loc) · 7.75 KB
/
main.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html>
<html>
<title>PY no code</title>
<meta name="description" content="Build Tkinter windows with a no-code platform">
<meta charset="UTF-8"> <!-- This defines the character set your website is written with -->
<meta name="viewport" content="width=device-width, initial-scale=1"> <!-- This makes your website responsive on different devices -->
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <!-- This is for better compatibility with Internet Explorer -->
<meta name="keywords" content="No code, python, tkinter, kai9987kai,tool">
<head>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
h2 {
color: #333;
}
#div1 {
width: 350px;
height: 200px;
padding: 10px;
border: 1px solid black;
background-color: #f9f9f9;
margin-bottom: 10px;
}
.draggable {
margin: 5px;
padding: 10px;
border: 1px solid #666;
background-color: #e0e0f0;
cursor: move;
transition: background-color 0.3s;
}
.draggable:hover {
background-color: #d0d0e0;
}
#code, #properties, #windowProperties {
margin-top: 20px;
padding: 10px;
border: 1px solid #666;
background-color: #f9f9f9;
white-space: pre-wrap;
}
#properties label, #windowProperties label {
display: block;
margin-top: 10px;
}
#properties input, #windowProperties input {
width: 100%;
padding: 5px;
margin-top: 5px;
}
#functionCode {
width: 100%;
height: 100px;
padding: 5px;
margin-top: 5px;
}
button {
margin-top: 10px;
}
</style>
</head>
<body>
<h2>Drag and Drop Demo</h2>
<p>Drag the elements below into the rectangle:</p>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<br>
<p class="draggable" id="drag1" draggable="true" ondragstart="dragStart(event)" onclick="editElement(event)">Draggable Text 1</p>
<p class="draggable" id="drag2" draggable="true" ondragstart="dragStart(event)" onclick="editElement(event)">Draggable Text 2</p>
<button class="draggable" id="drag3" draggable="true" ondragstart="dragStart(event)" onclick="editElement(event)">Draggable Button 1</button>
<button class="draggable" id="drag4" draggable="true" ondragstart="dragStart(event)" onclick="editElement(event)">Draggable Button 2</button>
<label class="draggable" id="drag5" draggable="true" ondragstart="dragStart(event)" onclick="editElement(event)">Draggable Label 1</label>
<label class="draggable" id="drag6" draggable="true" ondragstart="dragStart(event)" onclick="editElement(event)">Draggable Label 2</label>
<select class="draggable" id="drag7" draggable="true" ondragstart="dragStart(event)">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
<select class="draggable" id="drag8" draggable="true" ondragstart="dragStart(event)">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
<div id="properties">
<h3>Edit Element</h3>
<label for="title">Title:</label><br>
<input type="text" id="title"><br>
<label for="functionSelect">Function (for buttons only):</label><br>
<select id="functionSelect">
<option value="">None</option>
<option value="hello">hello</option>
<option value="goodbye">goodbye</option>
</select><br>
<label for="functionCode">Custom Function Code (Python):</label><br>
<textarea id="functionCode"></textarea><br>
<button onclick="saveProperties()">Save</button>
</div>
<div id="windowProperties">
<h3>Window Properties</h3>
<label for="windowTitle">Window Title:</label><br>
<input type="text" id="windowTitle"><br>
<label for="iconFile">Icon File:</label><br>
<input type="text" id="iconFile"><br>
<label for="alwaysOnTop">Always On Top:</label><br>
<input type="checkbox" id="alwaysOnTop"><br>
<label for="fullScreen">Full Screen:</label><br>
<input type="checkbox" id="fullScreen"><br>
<button onclick="saveWindowProperties()">Save</button>
</div>
<button onclick="showWindowProperties()">Edit Window Properties</button>
<button onclick="generateCode()">Generate Python Code</button>
<h2>Generated Python Code:</h2>
<pre id="code"></pre>
<script>
var selectedElement = null;
function allowDrop(ev) {
ev.preventDefault();
}
function dragStart(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
function editElement(ev) {
selectedElement = ev.target;
document.getElementById('title').value = ev.target.innerText;
document.getElementById('functionSelect').value = ev.target.getAttribute('data-function-name') || '';
document.getElementById('functionCode').value = '';
document.getElementById('properties').style.display = 'block';
}
function saveProperties() {
selectedElement.innerText = document.getElementById('title').value;
selectedElement.setAttribute('data-function-name', document.getElementById('functionSelect').value);
document.getElementById('properties').style.display = 'none';
}
function showWindowProperties() {
document.getElementById('windowProperties').style.display = 'block';
}
function saveWindowProperties() {
document.getElementById('windowProperties').style.display = 'none';
}
function generateCode() {
var pythonCode = 'from tkinter import *\nfrom tkinter import ttk\n\nroot = Tk()\n\n';
// Add default functions
pythonCode += `def hello():\n print("Hello, World!")\n\n`;
pythonCode += `def goodbye():\n print("Goodbye, World!")\n\n`;
// Add custom function code
var customCode = document.getElementById('functionCode').value;
if (customCode.trim() !== '') {
pythonCode += customCode + '\n\n';
}
// Window properties
pythonCode += `root.title("${document.getElementById('windowTitle').value}")\n`;
pythonCode += `root.iconbitmap("${document.getElementById('iconFile').value}")\n`;
if (document.getElementById('alwaysOnTop').checked) {
pythonCode += 'root.attributes("-topmost", True)\n';
}
if (document.getElementById('fullScreen').checked) {
pythonCode += 'root.attributes("-fullscreen", True)\n';
}
// Element properties
var div1 = document.getElementById('div1');
for (var i = 0; i < div1.children.length; i++) {
var child = div1.children[i];
if (child.tagName === 'P' || child.tagName === 'LABEL') {
pythonCode += `Label(root, text="${child.innerText}").grid(row=${i}, column=0)\n`;
} else if (child.tagName === 'BUTTON') {
var functionName = child.getAttribute('data-function-name');
pythonCode += `Button(root, text="${child.innerText}", command=${functionName || 'None'}).grid(row=${i}, column=0)\n`;
} else if (child.tagName === 'SELECT') {
pythonCode += 'cb = ttk.Combobox(root, values=[\n';
for (var j = 0; j < child.options.length; j++) {
pythonCode += ` "${child.options[j].text}",\n`;
}
pythonCode += `])\ncb.grid(row=${i}, column=0)\n`;
}
}
pythonCode += '\nroot.mainloop()';
// Output the Python code
var codeElement = document.getElementById('code');
codeElement.innerText = pythonCode;
}
</script>
</body>
</html>